1819796 Members
3106 Online
109607 Solutions
New Discussion юеВ

Ftp with a batch script

 
SOLVED
Go to solution
Tommy_6
Regular Advisor

Ftp with a batch script

I am trying to use ftp with a batch script from a HP 11.23 system. I cannot convince the owner of the remote server to switch to sftp, so I am stuck using ftp with a username and password. Does anyone know who to use ftp with a batch file? If not, is there a stable client out there that would support batch files on 11.23? Thanks in advance!!!

Tommy
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Ftp with a batch script

One of the two of these Perl scripts should do the trick for you (and you need to know 0 Perl just normal shell scripting):

ftpput.pl -h remhost -l mickey -p secret -A -d /aaa/bbb -t 3 file1 file2 file3
STAT=${?}
if [[ ${STAT} -ne 0 ]]
then
echo "FTP failed; status = ${STAT}" >&2
fi

This will login to remhost as user mickey, password secret, set ASCII mode, cd to /aaa/bbb, allow for up to 3 tries per file, and put file1, file2, and file3.

NOTE: You don't have to pass the password on the command line if you have a .netrc file -- just like "real" FTP.

Invoke as ftpput.pl -u for full usage. The good news is that the script will run unchanged on Windows as well if you install one of the free Perls for Windows.

If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Ftp with a batch script

.., and here is ftpget.pl for transfers in the other direction. Invoke as ftpget.pl -u for full usage.

If it ain't broke, I can fix that.
Tommy_6
Regular Advisor

Re: Ftp with a batch script

Thanks for the quick response, one thing I forgot to mention is that I need to use Passive transfer. Do you know if these script will handle Passive?
A. Clay Stephenson
Acclaimed Contributor

Re: Ftp with a batch script

Does a hog like slop?

If you do a man Net::FTP, you will see that passive mode is supported.

All you have to do is set the environment variable FTP_PASSIVE=1 and export before calling the Perl script.

You could also do it like this which would set it just for the command itself:

FTP_PASSIVE=1 ftpput.pl -h remhost ...


If it ain't broke, I can fix that.
Tommy_6
Regular Advisor

Re: Ftp with a batch script

The ftpput.pl script worked perfect with PASSIVE and ASCII requirements. Thanks again for the help!!