|  | 
	| 
		
			| Re: FTP Script with verification [message #97521 is a reply to message #97520] | Mon, 08 July 2002 12:08   |  
			| 
				
				
					| 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:  SFTP Script with verification [message #160241 is a reply to message #160201] | Fri, 24 February 2006 01:00   |  
			| 
				
				
					| 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  |  
			| 
				
				
					| 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 |  
	|  |  |