1834936 Members
2263 Online
110071 Solutions
New Discussion

Script for ftp

 
SOLVED
Go to solution
Victor_5
Trusted Contributor

Script for ftp

I am looking for a script which can do:

Working on the unix server side, ftp directories and files from window NT first, and make the same directories with window NT on the server side at the same time.

Your reply will be really appreciated.

Shawn

6 REPLIES 6
Sandip Ghosh
Honored Contributor

Re: Script for ftp

you can do something like this.

ftp -i -n <<-EOF
open www.xxx.xxx
user user_name password
bin
put file_log
quit
EOF

Sandip
Good Luck!!!
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Script for ftp

Hi:

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. Error checking in traditional scripts is far from easy; it can be done but why bother?
Perl makes it so simple.


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
If it ain't broke, I can fix that.
H.Merijn Brand (procura
Honored Contributor

Re: Script for ftp

Well spoken Clay! :)

Though for Win32, I'd go for the Cygwin solution, which makes it much more easy for HP-UX users to use Win32 instable working environments.

Cygwin comes with a 5.6.1 port and a ready to go GNU C compiler, so you can add your own missing modules if they use XS.

www.cygwin.com click on the setup icon in the top right corner

The documentation that comes with activbestate is very good and easy to browse
Enjoy, Have FUN! H.Merijn
Victor_5
Trusted Contributor

Re: Script for ftp

Hi guys

Thanks a lot.

I will have a try!
Victor_5
Trusted Contributor

Re: Script for ftp

Hi Clay

I just found I could not use perl in my unix server.
So, could you have some idea to use shell script to finish that

very appreciate

Shawn
Uday_S_Ankolekar
Honored Contributor

Re: Script for ftp

Hello Shawn,

Download perl from Hp's porting centre and install it. It's a "Good to have" and more important is It's a free stuff

http://hpux.cs.utah.edu/hppd/hpux/Languages/perl-5.6.1/

Havefun with perl...

-USA..
Good Luck..