I would like to copy only a new file from server1/remote_dir1 to server2/remote_dir2 each day. Each day on server1/remote_directory1 is created a new file and started with FMS_*.txt .
How to do it? Please write me example...
Copy only new file from server1 to server2 remote directory?
Moderator: DosItHelp
Re: Copy only new file from server1 to server2 remote direct
Code: Select all
copy "\\server1\remote_dir1\FMS_*.txt" "\\server1\remote_dir2"
Re: Copy only new file from server1 to server2 remote direct
But how just new file from server1\remote_dir1\FMS_*.txt to \\server2\remote_dir2?
Each day on server1\remote_dir1\ is a new file FMS_*.txt which only this file should be copied to server2\remote_dir2.
Each day on server1\remote_dir1\ is a new file FMS_*.txt which only this file should be copied to server2\remote_dir2.
Re: Copy only new file from server1 to server2 remote direct
Try this:
Code: Select all
@echo off
for /f "delims=" %%a in (' dir "\\server1\remote_dir1\FMS_*.txt" /b /od ') do set "file=%%a"
copy "\\server1\remote_dir1\%file%" "\\server1\remote_dir2"
Re: Copy only new file from server1 to server2 remote direct
for /f "delims=" %%a in (' dir "\\server1\remote_dir1\FMS_*.txt" /b /od ') do ----> I receive an error: The system cannot find the file specified. I think in this part is a problem : /b /od
Re: Copy only new file from server1 to server2 remote direct
I had to post in haste so I've changed the code above - which should work.
If it can't find the file then A) you don't have access to the server or B) the file is not there where you expect it to be or C) it is a foreign language and the codepage is wrong.
If it can't find the file then A) you don't have access to the server or B) the file is not there where you expect it to be or C) it is a foreign language and the codepage is wrong.
Re: Copy only new file from server1 to server2 remote direct
Here is complete code below. This code always copy all files from server1 to server2. I would like to copy only last file posted on server1 to server 2.
@echo off
pushd "c:\Batch\FTP_fms_froud_one\"
set "db=file_database_DO_NOT_DELETE.txt"
if not exist "%db%" type nul>"%db%"
del list.ftp 2>nul
del list2.ftp 2>nul
del filelist.txt 2>nul
del filelist2.txt 2>nul
set server_name=servername1
set username=username1
set password=username2
set remote_directory=OTHERS/out
set filespec=FMS_*.txt
for /f "delims=" %%a in ("%filespec%") do set filetype=%%~xa
echo ---------------------------------------------------------------------------
echo %date% %time% Begin Transfer
(
echo open %server_name%
echo %username%
echo %password%
echo cd %remote_directory%
echo ls %filespec%
echo quit
)>list.ftp
FTP -s:list.ftp >filelist.txt
for /f "delims=" %%a in (
'type "filelist.txt"^|find /i "%filetype%"^|find /i /v "ftp>"'
) do cmd /c >> filelist2.txt echo %%a
move /y filelist2.txt filelist.txt >nul
for /f "delims=" %%a in ('type "filelist.txt"') do (
find /i "%%a"<"%db%" >nul || >>filelist2.txt echo %%a
)
(
echo open %server_name%
echo %username%
echo %password%
echo binary
echo cd %remote_directory%
)>list2.ftp
for /f "delims=" %%a in ('type "filelist2.txt"') do (
>>list2.ftp echo mget %%a
>>list2.ftp echo y
>>"%db%" echo %%a
)
echo quit>>list2.ftp
FTP -s:list2.ftp
del list.ftp 2>nul
del list2.ftp 2>nul
del filelist.txt 2>nul
del filelist2.txt 2>nul
echo %date% %time% Done FTP Transfer
echo.
echo.
echo ---------------------------------------------------------------------------
echo Starting FTP upload
(
echo open 192.xxx.xx.xx
echo username of server2
echo password of server2
echo binary
echo mput FMS_*.txt
echo quit
)>list2.ftp
FTP -i -s:list2.ftp
del list2.ftp
echo %date% %time% Done FTP Upload
echo.
echo.
popd
@echo off
pushd "c:\Batch\FTP_fms_froud_one\"
set "db=file_database_DO_NOT_DELETE.txt"
if not exist "%db%" type nul>"%db%"
del list.ftp 2>nul
del list2.ftp 2>nul
del filelist.txt 2>nul
del filelist2.txt 2>nul
set server_name=servername1
set username=username1
set password=username2
set remote_directory=OTHERS/out
set filespec=FMS_*.txt
for /f "delims=" %%a in ("%filespec%") do set filetype=%%~xa
echo ---------------------------------------------------------------------------
echo %date% %time% Begin Transfer
(
echo open %server_name%
echo %username%
echo %password%
echo cd %remote_directory%
echo ls %filespec%
echo quit
)>list.ftp
FTP -s:list.ftp >filelist.txt
for /f "delims=" %%a in (
'type "filelist.txt"^|find /i "%filetype%"^|find /i /v "ftp>"'
) do cmd /c >> filelist2.txt echo %%a
move /y filelist2.txt filelist.txt >nul
for /f "delims=" %%a in ('type "filelist.txt"') do (
find /i "%%a"<"%db%" >nul || >>filelist2.txt echo %%a
)
(
echo open %server_name%
echo %username%
echo %password%
echo binary
echo cd %remote_directory%
)>list2.ftp
for /f "delims=" %%a in ('type "filelist2.txt"') do (
>>list2.ftp echo mget %%a
>>list2.ftp echo y
>>"%db%" echo %%a
)
echo quit>>list2.ftp
FTP -s:list2.ftp
del list.ftp 2>nul
del list2.ftp 2>nul
del filelist.txt 2>nul
del filelist2.txt 2>nul
echo %date% %time% Done FTP Transfer
echo.
echo.
echo ---------------------------------------------------------------------------
echo Starting FTP upload
(
echo open 192.xxx.xx.xx
echo username of server2
echo password of server2
echo binary
echo mput FMS_*.txt
echo quit
)>list2.ftp
FTP -i -s:list2.ftp
del list2.ftp
echo %date% %time% Done FTP Upload
echo.
echo.
popd