Command Line Script
Moderator: DosItHelp
-
- Posts: 7
- Joined: 01 Oct 2012 03:59
Command Line Script
Hi,
I am looking for a command line script to sen files to remote ftp server and command can additionally check every 5 minutes for the failed transfers and can resend?
I am looking for a command line script to sen files to remote ftp server and command can additionally check every 5 minutes for the failed transfers and can resend?
-
- Posts: 7
- Joined: 01 Oct 2012 03:59
Re: Command Line Script
Thanks for the quick reply.Below is the script i am currently using to send files every 1 hour.What i want this script to do is to after sending the files,check for the files in "Test1_TMP" for any issues in sending the files.I require this script to check 3 times at an interval of 5 minutes and attempt to send them.If even after 3 attempts,files are not being sent out,i require this script to send the files back to original"Test1" folder.
D:
cd\Test\Test1
if exist D:\Test\Test1\AR*.* (goto CheckTemp) else (goto Exit)
:CheckTemp
if exist D:\Test\Test1_TMP\AR*.* (goto EmailTemp) else (goto Move)
:EmailTemp
D:\Test2\Test3\gbmail -to maverick1183@gmail.com -h x.x.x.x -from root@testserver.com -s "Files exist in Test1_TMP folder. Pls check! "
:Move
del /q D:\Test2\Test3\Test4\dirAR.txt
Set DANNETFTP=D:\Test2\Test3\Test4\ftpNrename2.ftp
dir AR* /b > D:\Test2\Test3\Test4\dirAR.txt
:EmailUsers
D:\Test2\Test3\gbmail -to maverick1183@gmail.com -file D:\Test2\Test3\Test4\dirAR.txt -h x.x.x.x -from root@testserver.com -s "SUMMARY OF AR FILES SENT"
for /f %%A in (D:\Test2\Test3\Test4\dirAR.txt) do (call :PR01 %%A)
goto :EOF
:PR01
cd D:\Test\Test1
move %1 D:\Test\Test1_tmp\
cd D:\Test2\Test3\Test4
del /q current3.log
ftpandrename2.exe %1
ftp -i -s:%FTP% > current3.log
set filen=%1
:errorcheck
if errorlevel 0 goto filecheck
:filecheck
if exist D:\Test2\Test3\Test4\ftpAR.log goto ftplog
:Log
echo File Generated on > ftpAR.log
date /t > date.mst
time /t > time.mst
copy ftpAR.log+date.mst+time.mst ftpAR.log > 5.mst
:ftplog
echo Log generated on > ftp1.mst
date /t > date.mst
time /t > time.mst
copy current3.log+ftp1.mst+date.mst+time.mst current3.log > 3.mst
copy ftpAR.log+current3.log ftpAR.log > 4.mst
del *.mst
rem del current3.log
echo FTP Terminated
for /f "tokens=1" %%L in (D:\Test2\Test3\Test4\current3.log) do (call :PR02 %%L %filen%)
goto Continue
:PR02
rem echo %1
rem echo %filen%
if "%1"=="226" (move D:\Test\Test1_tmp\%filen% D:\Backup\Test4\)
goto :EOF
:Continue
rem move %1 D:\Backup\Test5
if exist D:\Test\Test1_tmp\%filen% (move D:\Test\Test1_tmp\%filen% D:\Test\Test1\)
goto :EOF
:Exit
exit
:EOF
D:
cd\Test\Test1
if exist D:\Test\Test1\AR*.* (goto CheckTemp) else (goto Exit)
:CheckTemp
if exist D:\Test\Test1_TMP\AR*.* (goto EmailTemp) else (goto Move)
:EmailTemp
D:\Test2\Test3\gbmail -to maverick1183@gmail.com -h x.x.x.x -from root@testserver.com -s "Files exist in Test1_TMP folder. Pls check! "
:Move
del /q D:\Test2\Test3\Test4\dirAR.txt
Set DANNETFTP=D:\Test2\Test3\Test4\ftpNrename2.ftp
dir AR* /b > D:\Test2\Test3\Test4\dirAR.txt
:EmailUsers
D:\Test2\Test3\gbmail -to maverick1183@gmail.com -file D:\Test2\Test3\Test4\dirAR.txt -h x.x.x.x -from root@testserver.com -s "SUMMARY OF AR FILES SENT"
for /f %%A in (D:\Test2\Test3\Test4\dirAR.txt) do (call :PR01 %%A)
goto :EOF
:PR01
cd D:\Test\Test1
move %1 D:\Test\Test1_tmp\
cd D:\Test2\Test3\Test4
del /q current3.log
ftpandrename2.exe %1
ftp -i -s:%FTP% > current3.log
set filen=%1
:errorcheck
if errorlevel 0 goto filecheck
:filecheck
if exist D:\Test2\Test3\Test4\ftpAR.log goto ftplog
:Log
echo File Generated on > ftpAR.log
date /t > date.mst
time /t > time.mst
copy ftpAR.log+date.mst+time.mst ftpAR.log > 5.mst
:ftplog
echo Log generated on > ftp1.mst
date /t > date.mst
time /t > time.mst
copy current3.log+ftp1.mst+date.mst+time.mst current3.log > 3.mst
copy ftpAR.log+current3.log ftpAR.log > 4.mst
del *.mst
rem del current3.log
echo FTP Terminated
for /f "tokens=1" %%L in (D:\Test2\Test3\Test4\current3.log) do (call :PR02 %%L %filen%)
goto Continue
:PR02
rem echo %1
rem echo %filen%
if "%1"=="226" (move D:\Test\Test1_tmp\%filen% D:\Backup\Test4\)
goto :EOF
:Continue
rem move %1 D:\Backup\Test5
if exist D:\Test\Test1_tmp\%filen% (move D:\Test\Test1_tmp\%filen% D:\Test\Test1\)
goto :EOF
:Exit
exit
:EOF
Re: Command Line Script
maverick1183 wrote:Thanks for the quick reply.Below is the script i am currently using to send files every 1 hour.What i want this script to do is to after sending the files,check for the files in "Test1_TMP" for any issues in sending the files.I require this script to check 3 times at an interval of 5 minutes and attempt to send them.If even after 3 attempts,files are not being sent out,i require this script to send the files back to original"Test1" folder.
You either have to parse the FTP log file to see if it was received ok (assuming it tells you) or you have to download the files and do a binary compare to see if they were transmitted and stored correctly.
-
- Posts: 7
- Joined: 01 Oct 2012 03:59
Re: Command Line Script
Thanks for the reply.I am not concerned here with the no of files transmitted.My script is scheduled hourly.I just want to make sure if during the scheduled time their is a disconnection with External FTP server,script automatically can detect that the files are still pending to be transmitted and can retry 3 times in the interval of 5 minutes each.
Re: Command Line Script
How were you planning on determining if the connection failed, and on which file?
-
- Posts: 7
- Joined: 01 Oct 2012 03:59
Re: Command Line Script
I am moving the files to folder "Test1_TMP" than i transfer them via FTP.So any of the files which are still their in the folder after running the script using scheduled task would be considered as a failed transfer
Re: Command Line Script
Your FTP script is missing and there is no log to view, so following the code is impractical
FWIW the errorlevel test has a logic flaw
FWIW the errorlevel test has a logic flaw
-
- Posts: 7
- Joined: 01 Oct 2012 03:59
Re: Command Line Script
Hi,
Can you help me setting it a loop that it checks for files 3 times in the test_temp folder and tries to send it out at an interval of 5 minutes?
Can you help me setting it a loop that it checks for files 3 times in the test_temp folder and tries to send it out at an interval of 5 minutes?
Re: Command Line Script
Here, schedule this. Alter the filespec in c:\test_temp and the FTP batch file name.
Code: Select all
@echo off
set c=0
:loop
if not exist "c:\test_temp\*.zip" goto :eof
set /a c=c+1
if %c% EQU 4 (
echo use email command here to tell you that there are ftp failures
goto :eof
)
call ftpsend.bat
ping -n 300 localhost >nul
goto :loop
-
- Posts: 7
- Joined: 01 Oct 2012 03:59
Re: Command Line Script
Thanks a ton..Its working like a charm