ftp client - Detecting FTP timeout in Windows batch script -
i have sql server agent job scheduled run daily. first of 2 steps calls ssis package, writes results of query file. second step executes batch file renames file include date, uploads file partner's ftp site, moves file archive directory , cleans up. works fine.
occasionally, however, no notification sent job completed successfully. when log server, see ftp.exe still running, file has not been uploaded nor moved archive. when terminate ftp process, job continues, moving file , cleaning up. @ job history reveals 2 different scenarios in these failed cases. first, connection made, last ftp output seen 150 opening data channel file transfer.--there no 226 transfer ok there successful job run. second scenario connection never established, script off , trying log in when there no connection open.
here script host, user, , pass munged:
@echo off setlocal d: cd d:\backups set file_name=ssis_output.txt set new_file_name=sdcl.%date:~-4,4%-%date:~-10,2%-%date:~-7,2%-00-00-00.txt set user=xxxxxxxxxxxxx set pass=xxxxxxxxxxxxx set host=xxxxxxxxxxxxx ren "%file_name%" "%new_file_name%" echo user %user%> ftpcmd.dat echo %pass%>> ftpcmd.dat echo bin>> ftpcmd.dat echo put %new_file_name%>> ftpcmd.dat echo close>> ftpcmd.dat echo bye>> ftpcmd.dat ftp -n -s:ftpcmd.dat %host% del ftpcmd.dat move %new_file_name% data_files what find way include error detection in batch file, if ftp connection either not established or times out before transfer completes, script recognizes , fails, allowing job fail , send appropriate notification. better, connection failure lead few additional attempts after appropriate pauses before surrendering , reporting failure.
edit: i'm not opposed installing different freeware ftp client, such winscp, if aid in arriving @ solution.
i spent weekend casting way windows ftp client exit on connection failure, unable find anything. i'm pretty sure not possible. in lieu of that, installed winscp, has console mode , decently scriptable. has reconnecttime option allows specify number of seconds process wait before attempting reconnect. in testing, job completed when disconnected ftp session server side several times. permanent disconnection caused program exit exit code of 1, sufficient sql server agent detect job failed , notify accordingly.
winscp doesn't seem consistent, though, in handling of disconnections. in trials, second disconnection of session caused program exit 1, while in others reconnected after many disconnections. landed on these settings ones maximizing probability of reconnections , successful job completion:
option batch on option reconnecttime 30 option confirm off
Comments
Post a Comment