- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- batch ftp
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
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
10-14-2002 12:35 PM
10-14-2002 12:35 PM
batch ftp
ftp
user
password
ls
quit
EOF
and I've tried placing the commands in a file and using it as input to the session and in both cases it gets hung up on the password prompt.
Any ideas?
Thanks
Johan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 12:43 PM
10-14-2002 12:43 PM
Re: batch ftp
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. You even get error trapping for free. 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("somehost",Debug => 0);
$ftp->login("cstephen","TopSecret");
$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 OK\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 also 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.
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. You only need Perl on the FTP client end.
It also becomes trivially easy to add looping to the code to retry the put/get a number of times if you get a staus of other than 2.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 12:45 PM
10-14-2002 12:45 PM
Re: batch ftp
you can supply a user and password for ech system to which you ftp. Once you get past the logon the rest of your script should work.
the ./netrc file goes in your home directory.
I use this to get patches from HP
machine ftp.itrc.hp.com login anonymous password me@my-company.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 12:55 PM
10-14-2002 12:55 PM
Re: batch ftp
#!/usr/bin/sh
{ echo "user username password
ls
quit" ; } ftp -i -n hostname
Put the appropriate "username", "password" and "hostname" in place and run it like so ..
$ ./ftp-test
Of course .. Clay's approach highly recommended.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 01:16 PM
10-14-2002 01:16 PM
Re: batch ftp
Johan,
What was wrong with Clay's answer?
perl is really the best solution!
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 01:20 PM
10-14-2002 01:20 PM
Re: batch ftp
I believe that the perl solution is probably the best one but the quickest resolution came from utilizing .netrc file.
I will adjust my rating accordingly in the future.
Sorry Clay.
johan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 01:54 PM
10-14-2002 01:54 PM
Re: batch ftp
ftp -n
..
..
quit
EOF
I agree the perl solution is better but sometimes shell is the quicker solution
-ETL
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2002 03:06 PM
10-14-2002 03:06 PM
Re: batch ftp
Good, because I like Clay's answer. 10 = best answer, 9-8 = very very good, 7-5 = good, 4-1 = not exactly, 0 = way off base.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2002 04:14 AM
10-15-2002 04:14 AM
Re: batch ftp
# ftp to NT server, get the backup report
#
(
echo "open 192.1.1.67"
echo "user anonymous root-corp"
echo "ascii"
echo "get checkfab.txt"
echo "delete checkfab.txt"
echo "bye"
) | ftp -i -n