- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Automated ftp question
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
12-12-2001 08:24 AM
12-12-2001 08:24 AM
Automated ftp question
I have wrote a basic automated ftp script and I would like to test a couple of more things but I am not sure how. I would like to test if the file the are trying to get or put exists, I would also like to test if the user was able to login on the ftp server sucessfully, does anyone have any idea how I would go about doing this? Thanks for you help in advance.
Adam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2001 08:31 AM
12-12-2001 08:31 AM
Re: Automated ftp question
Can't think of any damage that could result if one of the commands didn't work - can anyone else?
Share and Enjoy! Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2001 08:32 AM
12-12-2001 08:32 AM
Re: Automated ftp question
I don't think there is any control login within ftp. The only thing I can think of would be to execute you ftp script in debug, send that to a log file, then parse the log for the conditions you are looking for. It should be easy to search for login errors, or non-existant files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2001 08:48 AM
12-12-2001 08:48 AM
Re: Automated ftp question
TMP_FILE=/tmp/ftperrs.$$
ERRS=`egrep "^ 425|^ 426|^ 450|^ 451|^ 452|^ 500|^ 501|^ 502|^ 503|^
504|^ 530|^ 532|^ 550|^ 551|^ 552|^ 553|ERROR|not
received|Unknown host|Login incorrect|Permission denied|transfer
aborted|Connection timed out|Unable to connect|no data for|" [FTP
LOGFILE HERE]|grep -v " bytes "`
if [ -n "${ERRS}" ]; then
for LINE in `echo $ERRS`; do
echo "$LINE" >>$TMP_FILE
done
else
echo "There were no FTP errors" >$TMP_FILE
fi
--
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2001 10:31 AM
12-12-2001 10:31 AM
Re: Automated ftp question
ls /search_dir/filename local_filename
Then when I exit ftp grep for the file name in the local file created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2001 11:02 AM
12-12-2001 11:02 AM
Re: Automated ftp question
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 make 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.
Food for thought, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2001 11:49 AM
12-12-2001 11:49 AM
Re: Automated ftp question
I should have also mentioned that you need to man ftd for the meanings of the numerical FTP status codes. Again, in almost all cases, all you really need is the first digit; '2' - Good which is returned by the $ftp->status method.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2001 08:25 PM
12-12-2001 08:25 PM
Re: Automated ftp question
I'm attaching a script I had written sometime back for this purpose.
It transfers all files from a specified directory on a source m/c to a specified directory on the destination m/c.
After the ftp session terminates, it checks the file listing to ensure that all files are completely copied. If not, it retries the ftp.
Maybe you can pick up some hints from this script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2001 08:16 AM
12-13-2001 08:16 AM
Re: Automated ftp question
again for your help.