Operating System - HP-UX
1758798 Members
3114 Online
108875 Solutions
New Discussion юеВ

Re: Trapping ftp failures

 
Keyur Itchhaporia
New Member

Trapping ftp failures

Hello,
I am running ftp.exe from ms-dos. ftp calls a script file in order to get/put the files. The ftp process is logged into a file. Normally files are transferred, but sometimes the ftp transfer fails. Now the problem is that some ftp sites return proper error codes which i can trap by reading the ftp log file, but some ftp sites don't return error codes which confuses me whether the file transfered or not. Can anyone help me with this issue? Can anyone give me a better solution to acknowledge(verify) the files that are transferred? I want to trap the errors (if any) during ftp session.
Thanks,
Keyur
5 REPLIES 5
Gary L. Paveza, Jr.
Trusted Contributor

Re: Trapping ftp failures

The main problem I've found is that when running an ftp session, the last command is typically quit, which executes correctly (regardless of what happened before). The process then exits with a 0 return code.

What I have done is after a put, I do a get to a temp name, and compare the file sizes.
Chris Wilshaw
Honored Contributor

Re: Trapping ftp failures

FTP has its own internal codes;

Looking at a sample connection;

Connected to server1
220 server1 FTP server ready.
Name (server1:cwtest):
331 Password required for cwtest.
Password:
230 User cwtest logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd tmp
250 CWD command successful.
ftp> ls
200 PORT command successful.
150 Opening ASCII mode data connection for /usr/bin/ls.
total 80
-rw-r----- 1 cwtest sys 642 Apr 18 2001 archive.out
-rw-r----- 1 cwtest users 10095 Jun 11 2003 inv.1
-rw-r----- 1 cwtest sys 5490 Feb 14 2000 uc.out
-rw-r----- 1 cwtest sys 2475 Feb 14 2000 uc2.out
226 Transfer complete.
ftp> quit
221 Goodbye.


The 3 digits at the start of each line are the internal return codes for each command.

Look at the ftpd man page under the DIAGNOSTICS heading for full details.
Cesare Salvioni
Trusted Contributor

Re: Trapping ftp failures

hi
as chris told, ftp server respond to each command with a three number code answer.
The first one give the status (success, fail, need more) the other two describe better the mssage. You have to check these codes in your script and it could be not easy for the script to take lines and check them, for this i suggets you to use expect or tcltk.
With tcltk you can write one script running both on microsoft and hpux (as many other unix platform) with a lot of commands dedicated to ftp, server and client

see the link www.scriptics.com

hope it helps
A. Clay Stephenson
Acclaimed Contributor

Re: Trapping ftp failures

Whether you are FTP'ing using UNIX or Windows; one solution is to use Perl's Net::FTP module. You get error checking for free and it's very easy to use. For windows boxes, Active Perl (www.activeperl.com) is free and works very well. The nice part about this is that the script can work unchanged in Windows or UNIX.

The attached ftpget.pl should do just what you want. Invoke as
perl ftpget.pl -u for full usage. It will optionally automatically retry failed attempts and if you get an exit status of zero, you know all was well --- without having to look at any logs.


If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Trapping ftp failures

And here is a Perl script for the opposite direction, ftpput.pl. Again, invoke with a -u argument for full usage.

If it ain't broke, I can fix that.