Ftp Dos Script Error Handling
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 ftp shell script with error handling Us Learn more about Stack Overflow the company Business Learn more about hiring developers
Dos Ftp Errorlevel
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack
Ftp Error Codes
Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up MS-DOS FTP command in a batch file:
Powershell Ftp
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.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 ftp command line 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 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 u
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 or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x 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 only takes a minute: Sign up how to capture error conditions in windows ftp scripts? up vote 1 down vote favorite 1 I am using windows batch scripts to run ftp scripts automatically. Where the set http://stackoverflow.com/questions/10686730/ms-dos-ftp-command-in-a-batch-file-raise-error 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 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 http://stackoverflow.com/questions/31442020/how-to-capture-error-conditions-in-windows-ftp-scripts 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 sequence. Of course, you can test positive ftp messages rather... @ECHO OFF >NUL SETLOCAL enableextensions enabledelayedexpansion set "errsftp=0" ftp -n -i -s:c:\temp\myftpscriptfile.ftp >c:\temp\31442020.err 2>&1 for /F "tokens=1*" %%G in (c:\temp\31442020.err) do ( rem echo %%G [%%H] if "%%G"=="ftp>" ( set "line=%%H" set "errs=0" ) else ( set "reply=%%G %%H" Call :testreply Un
FTP Batch Moderator: DosItHelp Post new topic Reply to topic Page http://www.dostips.com/forum/viewtopic.php?t=1317 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 error handling 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: ftp dos script (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 Profi