Operating System - HP-UX
1821587 Members
4772 Online
109633 Solutions
New Discussion юеВ

ftp successfull confirmation

 
SOLVED
Go to solution
Links Moodley
Advisor

ftp successfull confirmation

I am sending files to a remote server,after uploading the files I need to do a get of the same files in order to confirm that the files have been successfully uploaded
11 REPLIES 11
George Liu_4
Trusted Contributor

Re: ftp successfull confirmation

depends on the ftp server configuration,

you may use
ls -l
in ftp session to check the file size.
Steven E. Protter
Exalted Contributor
Solution

Re: ftp successfull confirmation

Shalom,

It might be useful to do an md5sum checksum on the file both before and after to make sure the whole file got there unadulterated.

Further, if you use scripted ftp to put the file you can check the return code of the send process.

After any commmand in a script the variable $? contains the return code. echo $?

If you get a zero, the transmission was successful.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Links Moodley
Advisor

Re: ftp successfull confirmation

Hi, forgive my ignorance, I have not used the md5sum command before, perhaps you could send me the exact syntax of the command that I should use in the script
James R. Ferguson
Acclaimed Contributor

Re: ftp successfull confirmation

Hi:

Using any form of checksum or comparing the number of characters in the file on the source and destination servers is *not* guaranteed to yield an indication of a successful transfer.

Consider ASCII file transfers from/to UNIX and Windows platforms where carriage-returns are added or subtracted from linefeed record delimiters!

The 'ftpd' daemon offers a three-digit reply message that you can decode. See the manpages for 'ftpd(1M)' for more information. This, together with the message text it contains offer your salvation.

For instance, if I capture the '-v'erbose output of a transfer session into a logfile and parse that file at the end of the FTP session, I can find a successful transfer if I see something like:

226 transfer complete

The *exact* message will differ slightly for different FTP implementations, though.

Regards!

...JRF...
Mel Burslan
Honored Contributor

Re: ftp successfull confirmation

the first suggestion of cheking the filesize is not a viable option as, depending on the slack space on the target server, byte size of the file may change.

md5sum is not a command per-se. md5 is an algorithm, a complex one at that, to calculate the checksum of a given file. Calculation returns a unique string of characters for each individual file.

md5 application can be obtained from

http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/md5-1.00/

the down side of md5, it needs to be on both ends of the ftp connection and you need to be able to run it on the remote system and be able to see the output string. If you are not the administrator of the target system, you may have a problem.

There is a product called NDM (network data mover), sole purpose of which is to verify that data transmitted from one system to the other completes successfully and if not, depending on your configuration of this application, it may retry certain number of times more and notifies you of the failures. Product is now called connect:direct and sold by sterling commerce. Brief FAQ about this product can be found here:

http://www.proginetuk.co.uk/sections/faqs/126.htm

in the lack of ndm and admin capabilities on the target node, what you are doing is the only guaranteed way of verifying your data transfer was successful.

hope this helps.

________________________________
UNIX because I majored in cryptology...
A. Clay Stephenson
Acclaimed Contributor

Re: ftp successfull confirmation

Sometimes it's very hard to beat FTP's Net::FTP module not least because you get error checking for free.

The attached Perl script, ftpput.pl, will do all the stuff for you and all your shell script has to do is see if the exit status = 0; if so, all was well. It will even retry files automatically and not return a bad exit status until the specified number of retries are done. It will exit upon the first failed file.

#!/usr/bin/sh

typeset -i STAT=0
ftpput.pl -h remhost -l mickey -p secret -B -d /aaa/bbb/ccc myfile1 myfile2 myfile3
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "Okey Dokey"
else
echo "BAD FTP; status ${STAT}." >&2
fi
exit ${STAT}

------------------------------------------
This will login to remhost as user "mickey", password "secret", assert BINARY (-B) transfer mode, (-A would assert ASCII), cd to /aaa/bbb/ccc on remhost, and finally put myfile1, myfile2, and myfile3.

If any of the requests (e.g. cd -d /aaa/bbb/ccc) fail or the puts of the files fail then a non-zero exit status is returned. You don't have to pass the password on the command line because just like a real FTP client, it will read a .netrc file.

Invoke as ftpput.pl -u for full usage.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: ftp successfull confirmation

While I don't consider it necessary because if the put status = 0, all was well. If you absolutely must do a get then this script, ftpget.pl will do that job and the usage is very similar. Invoke as "ftpget.pl -u" for full usage. The same deal applies, if exit status = 0, all was well.
If it ain't broke, I can fix that.
Links Moodley
Advisor

Re: ftp successfull confirmation

Hi, I have used the script below and get errors, is there something wrong with my syntax?
typeset -i STAT=0
open astmachine
user REmbraceFTP Password1
type ascii
cd /FTPRemedy/Embrace/Inbox
lcd /usr1/EMBRACE/EMBRACE.AST/TRANSFERS
mput LMTEST
STAT=${?}
if [[${STAT} -eq 0 ]]
then
echo "Okay"
else
echo "BAD FTP; status ${STAT}." >&2
fi
exit ${STAT}
quit
Links Moodley
Advisor

Re: ftp successfull confirmation

Hi, when i do the ftp manually this is what i get, how do I ouput the results to a file.
230 User REmbraceFTP logged in.
Remote system type is Windows_NT.
ftp> type ascii
200 Type set to A.
ftp> cd /FTPRemedy/Embrace/Inbox
250 CWD command successful.
ftp> lcd /usr1/EMBRACE/EMBRACE.AST/TRANSFERS
Local directory now /usr1/EMBRACE/EMBRACE.AST/TRANSFERS
ftp> mput LMTEST
mput LMTEST? y
200 PORT command successful.
150 Opening ASCII mode data connection for LMTEST.
226 Transfer complete.
18 bytes sent in 0.00 seconds (390.62 Kbytes/s)
Arturo Galbiati
Esteemed Contributor

Re: ftp successfull confirmation

Hi,
you have to sue a here_document way:

ftp -inv <&1 1>ftp.log
open astmachine
user REmbraceFTP Password1
type ascii
cd /FTPRemedy/Embrace/Inbox
lcd /usr1/EMBRACE/EMBRACE.AST/TRANSFERS
mput LMTEST A
quit
END_OF_FTP

in this way you will hav ein ftp.log all the outputs.

HTH,
Art
A. Clay Stephenson
Acclaimed Contributor

Re: ftp successfull confirmation

You wrote:
lcd /usr1/EMBRACE/EMBRACE.AST/TRANSFERS
mput LMTEST
STAT=${?}

Is there something wrong with my syntax?

------------------------------------------
Is the Pope catholic?

More importantly, there is something wrong with your logic. You are mixing ftp and shell commands and expecting meaningful result. The ftp client in verbose mode will send a 3 digit result code after each but ftp command but trying to test this with ${?} is Looney Tunes. The ftp process has not terminated so there is no exit status with respect to ftp. You should also note that for most of the ftp commands, if the first digit of the 3 digit status is '2' then all is well.

Save yourself some trouble and use the ftpput.pl Perl script then ALL you have to do is simply examine the exit status of that command and if it is zero then all went well. It does all the tedious error checking for you.
If it ain't broke, I can fix that.