hI,
I want to copy latest file from windows server1 to another windows server2. On server1 with remote directory1 we have files starting with order by date:
FMS06112012.txt
FMS05112012.txt
FMS04112012.txt
FMS03112012.txt
FMS02112012.txt
FMS01112012.txt
FMS31102012.txt
FMS30102012.txt
FMS29102012.txt
FMS28102012.txt
.... up to 30 files....
Next day on server one will be FMS07112012.txt, next day FMS08112012.txt,....
I want to copy just last file(today this is FMS06112012.txt, tommorow will be FMS07112012.txt,...) daily from server1->remote directory1 TO server2 -> remote directory2.
For server1 I have to use this data:
server_name1 = v-sss-xxx
username1 = racauser
password1 = racapass
remote_directory1 = raca/OTHERS/out
For server2 I have to use this data:
server_name2 = 192.xxx.xx.xx
username2 = lalala
password2 = 123456
remote_directory2 = /spark_data/RangerData/
Please write me code.
Thanks in advance!
Copy latest file from one windows server to another one?
Moderator: DosItHelp
-
- Posts: 76
- Joined: 21 Dec 2011 14:21
Re: Copy latest file from one windows server to another one?
This will get you a little closer.
I chose the array solution (faster, easier) in case you wanted to step through the sets sequentially, so just sub Server1 with the actual address, same for Server2. Remove Echo on Copy Serv... to actually run copy the file.
notice that i didn't include script for the username and pass, no need to have the password in a file as a security risk. instead just make persistent routes for server1 and server2 and cache the passwords, that way all is hidden as it should be. you should have administrator rights for both servers.
Code: Select all
@echo off
setlocal enableextensions enabledelayedexpansion
set count=-0
for /f "tokens=1 delims= " %%a in ('dir /b /od FM????2012.txt') do (
set /a count+=1
set lastfile!count!=%%a
)
echo Oldest File is !lastfile1!
echo Newest File is !lastfile%count%!
echo Copy Server1\!lastfile%count%! Server2\Folder
endlocal
I chose the array solution (faster, easier) in case you wanted to step through the sets sequentially, so just sub Server1 with the actual address, same for Server2. Remove Echo on Copy Serv... to actually run copy the file.
notice that i didn't include script for the username and pass, no need to have the password in a file as a security risk. instead just make persistent routes for server1 and server2 and cache the passwords, that way all is hidden as it should be. you should have administrator rights for both servers.
Re: Copy latest file from one windows server to another one?
I have no control on servers, just they give me username and password. So in my way username and pasword for both servers must be included in this code. Coudl you write me code with usernames and passwords please?
-
- Posts: 76
- Joined: 21 Dec 2011 14:21
Re: Copy latest file from one windows server to another one?
Code: Select all
setlocal enableextensions enabledelayedexpansion
net use y: \\v-sss-xxx\raca\OTHERS\out racapass
net use z: \\192.xxx.xx.xx\spark_data\RangerData 123456
if exist y: if exist z: goto continue else echo No Networked Drives & goto end
:continue
set count=-0
for /f "tokens=1 delims= " %%a in ('dir /b /od y:\FM????2012.txt') do (
set /a count+=1
set lastfile!count!=%%a
)
echo Oldest File is !lastfile1!
echo Newest File is !lastfile%count%!
echo Copy Y:\!lastfile%count%! Z:
endlocal
:end
Re: Copy latest file from one windows server to another one?
Your script just open new cmd window.
In those lines you don't use usernames but only passwords. Is this correct?
net use y: \\v-sss-xxx\raca\OTHERS\out racapass
net use z: \\192.xxx.xx.xx\spark_data\RangerData 123456
In those lines you don't use usernames but only passwords. Is this correct?
net use y: \\v-sss-xxx\raca\OTHERS\out racapass
net use z: \\192.xxx.xx.xx\spark_data\RangerData 123456
-
- Posts: 76
- Joined: 21 Dec 2011 14:21
Re: Copy latest file from one windows server to another one?
izy wrote:Your script just open new cmd window.
In those lines you don't use usernames but only passwords. Is this correct?
net use y: \\v-sss-xxx\raca\OTHERS\out racapass
net use z: \\192.xxx.xx.xx\spark_data\RangerData 123456
You can't do a NET USE /? to show you more options? you got to at least try i think.
net use path password /user:domain\username is the generic
net use y: \\v-sss-xxx\raca\OTHERS\out racapass /USER:racauser
net use z: \\192.xxx.xx.xx\spark_data\RangerData 123456 /USER:lalala