- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- checking ftp return code
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2002 10:43 AM
06-07-2002 10:43 AM
I am using the following to retrieve files from an ftp server:
ftp -i -n $HOSTNAME <
bin
get $SOFTWARE
EOF
How can I check if the file was successfuly retrieved or check ftp return code?
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2002 10:49 AM
06-07-2002 10:49 AM
SolutionPls go thro this post :
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x284668c57f64d4118fee0090279cd0f9,00.html
Piyush
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2002 10:54 AM
06-07-2002 10:54 AM
Re: checking ftp return code
In the past, I used to do this stuff in the shell but now I NEVER do because I have found a much cleaner way to do it that makes error trapping duck soup. Do this stuff in Perl using the Net::FTP module which is available from http://www.cpan.org .
Here's how simple it can be:
#!/usr/bin/perl -w
use Net::FTP;
use strict;
my $ftp = Net::FTP->new("remotehost",Debug => 0);
$ftp->login("cstephen","top_secret");
$ftp->cwd("/tmp");
$ftp->get("myfile");
my $stat = $ftp->status;
my $full_stat = $ftp->code;
# $stat contains the first digit; usually all
# that you need to do is test if it is equal
# to 2. $full_stat contains the full 3-digit
# value but is seldom needed
printf("Status: %d Full Status: %d\n",$stat,$full_stat);
# Sample Test
if ($stat == 2)
{
print "Get was good\n";
}
else
{
print "Get was bad\n";
}
$ftp->quit;
I think if you start using this module you will never go back to shell scripting FTP. Moreover, these same scripts will run in the NT world. You can download a free version of perl for windows at http://www.activeperl.com.
Note that the answer is now the same on UNIX and NT and on the same subnet or across the net.
Notice that this method easily handles the error checking. If you like, you can use the shell for most of your script and simply use a bit a perl for the actual FTP transfers. In that case add the statement exit($stat) to the perl script and then your shell script does have a valid status indication.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2002 10:59 AM
06-07-2002 10:59 AM
Re: checking ftp return code
You can either go with Clay's solution, or route the output from the ftp process to a file, and then grep the file for the return codes and key error messages. I've posted a script that does this previously, I'll see if I can find the URL for that thread.
HTH
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2002 06:59 PM
06-08-2002 06:59 PM
Re: checking ftp return code
1. compute a checksum for the transfered file (command cksum) file_name before the transfer and put it into a file cksum_file_name
2. transfer a file_name
3. transfer a cksum_file_name
4. compute a checksum for an already transfered file
5. compar the new checksum and the checksum in a cksum_file_name
If the checksums are identical you are sure the file was not corrupted during the transfer.
Hope it helps