Home » Infrastructure » Unix » FTP Script with verification
FTP Script with verification [message #97520] Mon, 08 July 2002 08:44 Go to next message
Carol Marotti
Messages: 1
Registered: July 2002
Junior Member
Does anyone have an example of a UNIX ftp script that verifies the file was completly received from the remote machine?

Thanks,
CJ
Re: FTP Script with verification [message #97521 is a reply to message #97520] Mon, 08 July 2002 12:08 Go to previous messageGo to next message
Grant
Messages: 578
Registered: January 2002
Senior Member
Not sure how you would verify the file completed. Here is a script I use. It dynamically create the ftp script and runs it. I guess you could do some kind of "if" statement using "test" to see if the file transfered correctly. This pushes the file but it is easily modified to get.

#!/bin/ksh
#
# Script to use FTP using a file created dynamically.
# 3/15/01 Grant_howell
#
# Check if file exists.
if test -a $HOME/data/message.dat
then
PWD=`cat $HOME/passwd/oracle` # Get the password and plug it in PWD.
# Create the file to receive commands for FTP.
echo "Begin FTP Script..."
echo "open cronus" > ftptmp.scr
echo "user oracle $PWD" >> ftptmp.scr
echo "ascii" >> ftptmp.scr
echo "cd data" >> ftptmp.scr
echo "lcd data" >> ftptmp
echo "put message.dat" >> ftptmp.scr
echo "cdup" >> ftptmp.scr
echo "close" >> ftptmp.scr
ftp -inv < ftptmp.scr
echo "END FTP Script..."
rm ftptmp.scr
fi
Re: FTP Script with verification [message #97525 is a reply to message #97520] Tue, 09 July 2002 08:27 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
useful script - thanks
SFTP Script with verification [message #160201 is a reply to message #97525] Thu, 23 February 2006 21:00 Go to previous messageGo to next message
cindell55
Messages: 2
Registered: February 2006
Junior Member
Hi there..

Do u hv a Unix Script for SFTP ..for transferring data..

I dun no how to write down thru UNIX script..

Help.

TQ
Re: SFTP Script with verification [message #160241 is a reply to message #160201] Fri, 24 February 2006 01:00 Go to previous messageGo to next message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
I wrote a script once to verify FTP success. It captured the STDOUT of the FTP session to a file and then searched the results for the message number that indicates success (650 or something...?). I'm not working at that site any more, so I can't give it to you.

But, I can give you the best advice you'll ever get!

Don't use Shell scripts to FTP if you want to check for success. It's clunky and prone to failure. Use Perl. You just download the FTP module from CPAN, and you're almost done.

In your Perl script, you have 100% control over detecting Success or failure for every file you get or put.

I will NEVER use shell script again for FTP scripting.

_____________
Ross Leishman
Re: SFTP Script with verification [message #161189 is a reply to message #160241] Thu, 02 March 2006 08:34 Go to previous message
kshkid
Messages: 24
Registered: November 2005
Junior Member
here is a simple perl script for FTP
just try this,

use Net::FTP;
use Time::HiRes qw(gettimeofday);

my $timeCal1 = 0;
my $timeCal2 = 0;
my $noofarg = 0;

print "ftp started\n";
$noofarg = @ARGV;

$timeCal1 = gettimeofday ();

    $ftp = Net::FTP->new("servername1", Debug => 0)
      or die "Cannot connect to servername1: $@";

    $ftp->login("loginid", "pwd")
      or die "Cannot login ", $ftp->message;

    $ftp->cwd("/home/mad/")
      or die "Cannot change working directory ", $ftp->message;

    $ftp->get("client.c")
      or die "get failed ", $ftp->message;

    $ftp->quit;

$timeCal2 = gettimeofday ();


print "total time spent is ", ($timeCal2 - $timeCal1), "\n";
print "ftp ends\n";

exit 0
Previous Topic: How to find last modified date of a file
Next Topic: To acess Oracle 7.3 using HP-UX 10.20
Goto Forum:
  


Current Time: Thu Apr 25 15:09:48 CDT 2024