up vote 0 down vote favorite
share [g+] share [fb]

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 in the right direction to the general idea of how to do this, that would be great.

Thanks.

link|improve this question

feedback

3 Answers

up vote 3 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 System.Net.WebClient
$wc.DownloadFile($url, $destination)

If you need to do more complicated things I'd start by looking at http://msdn.microsoft.com/en-us/library/ms229718.aspx Those examples are in C#, but it should be pretty easy to convert them to PS.

A script built in this way can list a dir and loop over the files downloading the ones you want. If there are any errors you can handle them on a per file level how you like.

link|improve this answer
feedback

It's common for console utilites to return some code indicating that error was happened, they are described e.g. here. If ftp exits after some error it probably returns a non-zero code indicating fault. IMHO there is no simple way to parse output of a program in batch files, but you can check errorlevel and save a logfile (using output stream redirection: command args >log) or send it by email.

link|improve this answer
Are there any ftp specific error levels, indicators of what the error was, or am I only given "something" went wrong? Thank You. – Tommy Jan 21 '10 at 20:09
Looks like this is a custome error check: experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/… – Tommy Jan 21 '10 at 20:11
Yes, that script is parsing ftp's output (it does not use ftp errorlevels, only find). It is what I called 'complicated' in my post, through. Sorry, I cannot provide you more detail about batch files and ftp because I do not have an accessible Windows system now. – whitequark Jan 21 '10 at 20:27
feedback

That error message is a FTP specific error, and is because your firewall will by default disable FTP connections (this is a good thing!).

You can ignore this message as it will not affect your computer in any way.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.