Ftp Error Handling In Dos
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the dos ftp errorlevel workings and policies of this site About Us Learn more about Stack ftp shell script with error handling Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs ftp error codes 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 dos errorlevel them; it only takes a minute: Sign up How to capture the ftp error code in batch scripts? up vote 4 down vote favorite 1 I have a somewhat related, but different questions here. I have a batch script (*.bat file) such as this: @ftp -i -s:"%~f0"&GOTO:EOF open ftp.myhost.com myuser mypassword !:--- FTP commands below here --- lcd "C:\myfolder" cd
Powershell Ftp
/testdir binary put "myfile.zip" disconnect bye Basically this is a script that uploads a zip file to a ftp site. My question is that, the upload operation can fail from time to time ( the remote ftp is not available, "myfile.zip" is non-existent, upload operation interrupted and whatnot), and when such unfortunate things happen, I want my bat file return 1 ( exit 1). It would be great if my upload wasn't successful, the ftp would throw an exception ( yes, like exception in C++), and I would have a catch-all exception that catches it and then exit 1, but I don' think this is available in batch script. What is the best way to do what I need here? ftp batch-file share|improve this question asked Aug 23 '11 at 8:40 Graviton 36.1k99331509 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote You can redirect the output to a log file and when the ftp session is finished the file can be parsed. @ftp -i -s:"%~f0" > log.txt & GOTO :p
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
Ftp Command Line
more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Super User Questions Tags Users Badges Unanswered Ask Question _ Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up http://stackoverflow.com/questions/7158295/how-to-capture-the-ftp-error-code-in-batch-scripts and rise to the top How do I check the outcome of a ftp script with a bat file? [closed] up vote 2 down vote favorite 2 I have a .bat file that runs a ftp script, grabbing files from the server and copying them to my machine. Works great. I now want this .bat file to report if any of these errors occured. If you could point me http://superuser.com/questions/98903/how-do-i-check-the-outcome-of-a-ftp-script-with-a-bat-file in the right direction to the general idea of how to do this, that would be great. Thanks. windows ftp script batch share|improve this question edited Jan 21 '10 at 23:51 asked Jan 21 '10 at 19:38 Tommy 3042716 closed as off-topic by Jens Erat, Kevin Panko, KronoS, digitxp, Mokubai♦ Aug 12 '14 at 21:02 This question appears to be off-topic. The users who voted to close gave this specific reason:"This question is not about computer hardware or software, within the scope defined in the help center." – digitxp, MokubaiIf this question can be reworded to fit the rules in the help center, please edit the question. add a comment| 5 Answers 5 active oldest votes up vote 4 down vote accepted To be honest I've never had great success using fixed FTP scripts. Even if you deal with the return codes its hard to know exactly what went wrong. I'd recommend using PowerShell or Python for the job instead. Both these have access to an FTP client that can be dynamically controlled. You'll know exactly whats worked or failed, and be able to deal with the issue then and there. Simple Example in PS $url = "ftp://ftp.foo.com/bar.txt" $destination = "c:\foo\bar.txt" $wc = New-Object Syste
FTP Batch Moderator: DosItHelp Post new topic Reply to topic Page 1 of 1 [ 4 posts ] http://www.dostips.com/forum/viewtopic.php?t=1317 Print view Previous topic | Next topic Author Message SteveE Post http://www.angelfire.com/home/jasonvogel/dos_ftp_batch_return_code.html 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 ftp error 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 ftp error handling 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
FTP session REM ============================================================ echo Initial Errorlevel = %ERRORLEVEL% echo open servername > ftpscr.dat echo user userid1 password >> ftpscr.dat echo put c:\temp\ftptest\test.bat>> ftpscr.dat echo bye>> ftpscr.dat REM ============================================================ REM If there is an error during the FTP execution, FIND returns a 1 REM which is stored in the environment variable %ERRORLEVEL% REM otherwise a 0 is stored for successs REM ============================================================ ftp -n -s:ftpscr.dat | FIND "Transfer complete" echo %ERRORLEVEL% if %ERRORLEVEL%==1 goto error goto end :error echo Error occurred during FTP :end echo Done REM del ftpscr.dat Home Mail : jasonvogel@no-spampoboxes.com (remove the "NO-SPAM") Forwarding Homepage : http://www.poboxes.com/jasonvogel Copyright © : 1997 - 2005