Ftp Batch 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 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 ftp shell script with error handling 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 error codes 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 powershell ftp as this: @ftp -i -s:"%~f0"&GOTO:EOF open ftp.myhost.com myuser mypassword !:--- FTP commands below here --- lcd "C:\myfolder" cd /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 (
Ftp Command Line
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 :parse open ftp.myhost.com myuser mypassword !:--- FTP commands below here --- lcd "C:\myfolder" cd /testdir binary put "myfile.zip" disconnect bye :parse for /F "delims=" %%L in (log.txt) Do ( ... parse each line ) share|improve this answer answered Oct 6 '13 at 20:38 jeb 43k998118 add a comment| up vote 0 down vote Your only option in batch files that I know of is to use the "IF ERRORLEVEL" syntax, which requires your ftp client to return a non-zero error code. http://www.robvanderwoude.com/errorlevel.php is a good reference guide. Unfortunately I do not if the standard Windows ftp client returns non-zero error codes, so you may have to code your own if this is a requirement. This link suggests that it does not return an error code, but
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 http://stackoverflow.com/questions/7158295/how-to-capture-the-ftp-error-code-in-batch-scripts 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 script fail. I am having difficulty figuring out how to http://stackoverflow.com/questions/31442020/how-to-capture-error-conditions-in-windows-ftp-scripts 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 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\myftpscrip
activation email? 1 Hour 1 Day 1 Week 1 Month Forever Login with username, password and session length Forum only search News: Home Help Login Register Computer Hope » Microsoft » Microsoft DOS http://www.computerhope.com/forum/index.php?topic=15354.0 » FTP Batch Script « previous next » Print Pages: [1] Go Down http://unix.ittoolbox.com/groups/technical-functional/shellscript-l/error-handling-if-ftp-fails-1208688 Author Topic: FTP Batch Script (Read 6927 times) 0 Members and 1 Guest are viewing this topic. HelpPls Guest FTP Batch Script « on: November 18, 2005, 11:09:47 AM » I have batch script for simple FTP (import/export) with out any error handling.I would like write error checking so that i can catch error handling the server time out, down. or any other reason batch file fail.Any example of how to take care of this task ? Here is my sample code:Code: [Select]c:
cd\some file destination
call format
del UpdateLog16.txt
ren UpdateLog15.txt UpdateLog16.txt
ren UpdateLog.txt UpdateLog1.txt
ftp -n -i -s:c:2ndbatch.txt > UpdateLog.txt
Here is the 2nd batch file:
open some FTP Site
user
password
cd /some dir...
bin
mput *.jpg
close
Thanks In Advance Logged Singleton06 Guest Re: FTP Batch Script « Reply ftp batch error #1 on: November 18, 2005, 12:19:20 PM » are you saying like a way to trouble shoot what is going on??? If thats what you're refering too, i would suggest putting pauses in there to watch what each line does specifically.... and see where it goes wrong that way... Logged Sohil Kharva Guest Re: FTP Batch Script « Reply #2 on: November 18, 2005, 12:58:00 PM » The batch script that i runs twice a day. And sometimes it failes and i would just like to figure out why and when it failes.Maybe out put the result to log file or something . Logged Singleton06 Guest Re: FTP Batch Script « Reply #3 on: November 18, 2005, 01:06:31 PM » if it fails everytime??? the only suggestion i have is that when i'm building batch files for some stuff that i work on, i put pauses in a bunch of areas, and see if it tells me "error blah blah has occured" then i can go off of that. Try to put pauses in there, other than that i have no idea how to input error messages into files or anything... « Last Edit: November 18, 2005
Technology and Trends Enterprise Architecture and EAI ERP Hardware IT Management and Strategy Java Knowledge Management Linux Networking Oracle PeopleSoft Project and Portfolio Management SAP SCM Security Siebel Storage UNIX Visual Basic Web Design and Development Windows < Back CHOOSE A DISCUSSION GROUP Research Directory TOPICS Database Hardware Networking SAP Security Web Design MEMBERS Paul_Pedant DACREE MarkDeVries MacProTX Inside-ERP VoIP_News Inside-CRM I_am_the_dragon maxwellarnold Michael Meyers-Jouan TerryCurran Chris_Day Andrew.S.Baker Ramnath.Awate JoeTorre Locutus bracke Dennis Stevenson PCMag Craig Borysowich DukeGanote Richard mircea_luca iudithm Nikki Klein Clinton Jones AbhaiTripathi knowscognosdoi Iqbalyk bluesguyAZ59 COMPANIES HP, Voltage Security and ... Hitachi America, LTD Arbor Networks, Inc. Quest Software View All Topics View All Members View All Companies Toolbox for IT Topics UNIX Groups Ask a New Question Shell Script The Shell Script group is a forum where peers share technical expertise, solve problems, and discuss issues related to the use of Shell Scripts to configure UNIX or UNIX-like systems. Home | Invite Peers | More UNIX Groups Your account is ready. You're now being signed in. Solve problems - It's Free Create your account in seconds E-mail address is taken If this is your account,sign in here Email address Username Between 5 and 30 characters. No spaces please The Profile Name is already in use Password Notify me of new activity in this group: Real Time Daily Never Keep me informed of the latest: White Papers Newsletter Jobs By clicking "Join Now", you agree to Toolbox for Technology terms of use, and have read and understand our privacy policy. Error handling if FTP fails Bhavanam asked Oct 16, 2006 | Replies (9) Hi Iam writing a shellscript to transfer a file from one server to another server. using FTP src Dest Address, FTP Dest directory, Put file it is working properly. if anything goes wrong , i want to write a error handling in such cases if any one help me, i will be thankful to them in Advance Very urgent Join this group Popular White Paper On This Topic 5 Best Practices for Business Intelligence 9Replies Best Answer 0 Mark this reply as the best answer?(Choose carefully, this can't be changed) Yes | No Saving... Dimitre Radoulov repl