Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get feedback from 'ftp' command?

Status
Not open for further replies.

Kimed

Programmer
May 25, 2005
104
0
0
LT
I apologize in advance if this is a wrong part of the forum, but in others it seemed even less relevant.

So, I'm trying to make a FOXPRO program to send some files from an FTP server (if you're going to say there's a FOXPRO forum here - the problem I have is not on FOXPRO's part at all). Since FOXPRO itself doesn't have commands for that, I form a text file with commands like
Code:
open (ftp-address)
(username)
(password)
get (filename)
close
bye
, then run an external command "ftp -s:scriptname", and all's dandy. But what if something goes wrong? For example, there's no connection, or the file is missing. In the manual mode, it becomes evident immediately, but the batch command continues to run void, goes back to the calling program, and that one thinks everything went right. The question is, while studying online help on 'ftp' command, I couldn't find any hint that the command returns some error codes or has internal 'if-then' type subcommands. Is there *any* way to make a program calling 'ftp' with a batch script aware of possible failures?

Thanks.
 
There are a couple ways you could do this. This may not be pretty, but I would use the following method. I'm not to familiar with foxpro, but since you call the external ftp command, call a batch file instead, and within that batch file, pipe your ftp command to the "find" command, looking for whatever constitutes a success event, in my example, successfully "putting" a file:

ftp -s:filename.txt | find "226 Transfer complete."

Then, you would perform your conditional on the %errorlevel% variable; you will either get a 0 (success) or a 1 (failure) from the find command, you can then execute whatever you want to based on that result, e.g.:

if not errorlevel 0 error-report.bat


You can make error-report.bat send you a message or terminate your process, whatever you want it to do. And of course it doesn't necessarily have to be a batch file.
I think I've got all the syntax correct. You will obviously have to tailor this to whatever you're trying to accomplish, but it seems doable to me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top