Ftp Error Handling Batch File
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers ftp shell script with error handling or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x
Dos Ftp Errorlevel
Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it
Ftp Batch File Commands
only takes a minute: Sign up MS-DOS FTP command in a batch file: raise error up vote 3 down vote favorite 1 In MS-DOS (Windows 2003 R2 Server), I have a batchfile which has the FTP command in it, eg:-
Ftp Error Codes
FTP.CMD ------- cd d:\extracts\scripts ftp -i -s:ftp_getfile.ftp exit I would like the batch file to raise and return an error level 1 for failure instead of 0, so that the calling batchfile can deal with it. The error could be caused by the FTP server being down. Right now, nothing is returned to indicate an error condition occured. Please can someone advise? Thanks! :) windows error-handling batch-file ftp ms-dos share|improve this question asked May 21 '12 at 14:02 Learner74 6839 ftp batch script add a comment| 2 Answers 2 active oldest votes up vote 2 down vote Maybe too late, but it is possible. I'm running the following script to check for errors in the text that's returned by the FTP script. If you know the error text that's returned by FTP, then that's what you look for with the 'find' command. The ftp commands are in a file called ftp.inp, just check out the help of FTP on how to use '-s'. ftp -s:ftp.inp > ftp.log find /I /C "not connected" ftp.log IF NOT ERRORLEVEL 1 GOTO FTPERROR find /I /C "not found" ftp.log IF NOT ERRORLEVEL 1 GOTO FTPERROR find /I /C "failed" ftp.log IF NOT ERRORLEVEL 1 GOTO FTPERROR REM --- no errors found GOTO :END :FTPERROR REM --- error found :END share|improve this answer answered Jul 19 '12 at 4:40 Martijn S 212 Thanks for the reply Martin, I eventually solved this by using a third-party FTP command-line client called WinSCP portable winscp.net/eng/download.php , this can raise several error codes upon exit. –Learner74 Jun 4 '13 at 14:34 add a comment| up vote 1 down vote As per this question: How to capture the ftp error code in batch scripts? The windows FTP command doesn't support this behaviour (or PASV mode) and is basically next to useless. You might want to try NcFtp instead. It's free, small, portable, and has decent error codes. share|improve t
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about powershell ftp Stack Overflow the company Business Learn more about hiring developers or posting ads windows ftp command with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow ftp script is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up how to capture error conditions in windows ftp scripts? up vote 1 down http://stackoverflow.com/questions/10686730/ms-dos-ftp-command-in-a-batch-file-raise-error vote favorite 1 I am using windows batch scripts to run ftp scripts automatically. Where the set of ftp commands I want run is saved in a file. example: @echo off ftp -n -i -s:c:\temp\myftpscriptfile.ftp I have used the %ERRORLEVEL% syntax to successfully capture error conditions in the batch commands. My challenge is the ftp script command is always returning an ERRORLEVEL of 0 even when the commands inside the http://stackoverflow.com/questions/31442020/how-to-capture-error-conditions-in-windows-ftp-scripts script fail. I am having difficulty figuring out how to have the ftp script actually return or trap when errors occur inside it. It will simply run through the commands blindly and even though i can see the errors echoed on screen I can't capture them as an ERRORLEVEL.. Sample screen shot of trying script which fails to login and then echoing the ERRORLEVEL which shows a zero.. ftp> open fubar.test.com Unknown host fubar.test.com ftp> user test test Not connected. ftp> ascii Not connected. ftp> cd /home/test/dirname Not connected. ftp> mput C:\Test\test*.txt Not connected. ftp> close Not connected. ftp> quit .0 batch-file ftp share|improve this question asked Jul 15 '15 at 22:06 Bernardo Sicard 61 You should better use a different command-line FTP client. –Martin Prikryl Jul 19 '15 at 8:20 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote Use find: ftp -n -i -s:c:\temp\myftpscriptfile.ftp 2>&1|find "Unknown host">nul if %errorlevel%==0 ( echo Error! ) share|improve this answer answered Jul 15 '15 at 22:52 wOxxOm 14.8k21538 add a comment| up vote 1 down vote Parse ftp communication using for /F command. Possible approach in next script. Caveat: there supposedly exist some ftp error message(s) not included in given test seq
for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Ask a Question Ask for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Expand Search Submit Close Search Login Join Today https://www.experts-exchange.com/questions/26509565/FTP-Batch-file-with-error-handling.html Products BackProducts Gigs Live Careers Vendor Services Groups Website Testing Store Headlines Experts Exchange > Questions http://www.dostips.com/forum/viewtopic.php?t=1317 > FTP Batch file with error handling Want to Advertise Here? Solved FTP Batch file with error handling Posted on 2010-09-29 MS DOS 2 Verified Solutions 26 Comments 3,346 Views Last Modified: 2012-05-10 I have a batch file that uploads all PDFs in the folder containing the batch file and then deletes the PDFs. However even on upload or connection failures the files are deleted. ftp error I need help to only delete files that uploaded successfully. Windows XP SP3 Here is the code: @echo off echo DO NOT CLOSE echo userusernamej> ftpcmd.dat echo password>> ftpcmd.dat echo bin >> ftpcmd.dat echo prompt off>> ftpcmd.dat echo cd data/index >> ftpcmd.dat echo mput *.pdf >> ftpcmd.dat echo quit>>ftpcmd.dat ftp -n -s:ftpcmd.dat ftphost del *.pdf del ftpcmd.dat 0 Question ftp error handling by:mackeyrj Facebook Twitter LinkedIn Google LVL 33 Active 2 days ago Best Solution byknightEknight @echo off echo DO NOT CLOSE echo userusernamej> ftpcmd.dat echo password>> ftpcmd.dat echo bin >> ftpcmd.dat echo prompt off>> ftpcmd.dat echo cd data/index >> Go to Solution 26 Comments LVL 2 Overall: Level 2 Message Expert Comment by:DrewWatson2010-09-29 http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_23415478.html abit of an old post but ftp.exe hasnt changed in years aswell! :) 0 LVL 2 Overall: Level 2 Message Expert Comment by:tibidoudou2010-09-29 Hi, I haven't tried this, but I think it should work. @echo off echo DO NOT CLOSE echo userusernamej> ftpcmd.dat echo password>> ftpcmd.dat echo bin >> ftpcmd.dat echo prompt off>> ftpcmd.dat echo cd data/index >> ftpcmd.dat echo mput *.pdf >> ftpcmd.dat echo quit>>ftpcmd.dat ftp -n -s:ftpcmd.dat ftphost && goto OK goto END :OK del *.pdf del ftpcmd.dat :END 0 LVL 33 Overall: Level 33 MS DOS 11 Message Active 2 days ago Accepted Solution by:knightEknight2010-09-29 @echo off echo DO NOT CLOSE echo userusernamej> ftpcmd.dat echo password>> ftpcmd.dat echo bin >> ftpcmd.dat echo prompt off>> ftpcmd.dat echo cd data/index >> ftpcmd.dat echo mput *.pdf >> ftpcmd.dat echo mls *.pdf movedfiles.txt echo quit>>ftpcmd.dat ftp -n -s:ftpcmd.dat ftphost if exist movedfiles.txt f
FTP Batch Moderator: DosItHelp Post new topic Reply to topic Page 1 of 1 [ 4 posts ] Print view Previous topic | Next topic Author Message SteveE Post subject: Error Catch in FTP BatchPostPosted: 02 Sep 2010 14:17 Offline Joined: 02 Sep 2010 12:24 Posts: 2 I have a simple batch file that runs 4 functions and sends some files via FTP to our server1: collects any of file type *.swy from drop point2: FTP them to Server3: Copies files *.swy to backup directory4: Deletes files *.swy from Drop PointI need to error catch if the files being FTP’d and not, so that they don’t get deleted from the drop point until ftp’dHere is my batch file: (this runs fine as is just need to capture should Myserver be down etc)cd \\Test\db\CFS\WWICFPodsftp -s:\\Test\db\CFS\WWICFPods\Script.txtcopy \\Test\DB\Cfs\WWICFPods\*.swy \\Test\DB\Cfs\WWICFPods\bakdel \\Test\DB\Cfs\WWICFPods\*.swyy======================================================================Here is the FTP Script.txt fileopenMyserverMyLogonMyPasswordCD /cluster/cfs/u/cim3/outray/filedropPWDasciipromptmput \\Test\db\CFS\WWICFPods\*.swybyeany help / advise appreciated Top Profile Reply with quote ghostmachine4 Post subject: Re: Error Catch in FTP BatchPostPosted: 02 Sep 2010 19:31 Offline Joined: 12 May 2006 01:13 Posts: 319 Win32 ftp is not really a good ftp client to do automation. Use a good programming language like Perl/Python that have FTP libraries with capabilities for error debugging and trapping. Eg of Perl's Net::FTP Top Profile Reply with quote SteveE Post subject: Re: Error Catch in FTP BatchPostPosted: 05 Sep 2010 14:38 Offline Joined: 02 Sep 2010 12:24 Posts: 2 Thanks for the advise but I am stuck with the basic cmd FTP tool if you are saying I have no options in this are then thanks for your time, I will just have to manage without error catchingSteve Top Profile Reply with quote ghostmachine4 Post subject: Re: Error Catch in FTP BatchPostPosted: 05 Sep 2010 18:54 Offline Joined: 12 May 2006 01:13 Posts: 319 you may want to try the -d switch for debugging.... that's about it i can recommend. Top Profile Reply with quote Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 yearSort by AuthorPost timeSubject AscendingDescending Post new topic Reply to topic Page 1 of 1 [ 4 posts ] Board index » DosTips - Dos Batch » DOS Batch Forum All times are UTC-06:00 Who is online Users browsing this forum: Yahoo [Bot] and 3 guests You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post a