1834604 Members
3629 Online
110069 Solutions
New Discussion

Re: Unattended FTPing

 
SOLVED
Go to solution
Karla Robinson
Occasional Contributor

Unattended FTPing

I'm trying to FTP from HPUX to AS/400 in unattended mode. I can get to the server, no problem, but I can't get it to recognize the userid and password information, or for that matter that this information is even being sent.

The same sequence of commands works fine when performed manually. Man on ftp in HPUX and HELP on FTP in AS/400 reveal that not all subcommands exist in both versions of FTP.

Any ideas?
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor
Solution

Re: Unattended FTPing

Hi:

There are a multitude of script examples and suggestions in thie Forum. A search will easily find them. Here are two possible scripts:

#!/usr/bin/sh
ftp -n << EOF
verbose
open thehost
user uuu ppp
get /tmp/stuff
close
EOF

...

#!/usr/bin/sh
{ echo "open thehost
user uuu ppp
hash
mput *
close"
} | ftp -i -n -v 2>&1 | tee /tmp/ftplog.$$

Regards!

...JRF...
Geoff Wild
Honored Contributor

Re: Unattended FTPing

Did you setup the .netrc file?

Is your script like this:

#!/bin/sh
#
# FTP printjob
#
#set -x
TIMESTAMP=`/usr/bin/date`
HOSTADDRESS=XXX.XXX.XXX.XXX
FILENAME=`basename $1`
LOGDIR=/somedirectory/
LOGFILE=$LOGDIR$FILENAME.ftplog
XferMode=bi
LOCALDIR=/anotherdirectory
echo "LOGFILE FOR JOB $FILENAME AT $TIMESTAMP" > $LOGFILE
ftp -v $HOSTADDRESS <> $LOGFILE
$XferMode
lcd $LOCALDIR
put $FILENAME
dir $FILENAME
pass
bye
EndFTP

STATUS=`grep complete $LOGFILE`
if [[ $STATUS != "" ]]; then
ERROR=0
l_rc=0
else
ERROR=1
fi
exit $ERROR



RGds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Bryan D. Quinn
Respected Contributor

Re: Unattended FTPing

Hey Karla,

We do this from and HPUX 11.0 box to an AS/400. Although I don't recall encountering that kind of problem, what we do is have a primary script create a secondary (ftp script). Here is an example of what we do:

## BUILD FTP SCRIPT ##

echo open ip.add.of.as400 > $tmp_file
echo user username password >> $tmp_file
echo cd directory >> $tmp_file
echo lcd directory >> $tmp_file
echo get some_file >> $tmp_file
echo close >> $tmp_file
echo quit >> $tmp_file

## BEGIN FTP ##

ftp -n -v < $tmp_file

We have not had any problems with this arrangement. Runs four times a day everyday.

Hope this helps!
-Bryan
Patrick Wallek
Honored Contributor

Re: Unattended FTPing

Can you show us the script you are using?

Are you doing something like:

ftp -inv as400 << EOF
user username password
dir
get
put
EOF

You basically just need to emulate what you do manuall with the syntax as above. You might also consider using a .netrc file which allows you to specify a machine name, username and passwd and when you FTP it automatically logs you in. The .netrc has to be in the home directory of the user that is doing the FTP.

The syntax of it is:

# cat .netrc
machine machine_name login user_name password abc123

It's permissions must be 500 and it must be owned by the user that will be using it.
A. Clay Stephenson
Acclaimed Contributor

Re: Unattended FTPing

My favorite method is to use the Net::FTP Perl module. If you have Perl 5.6.1 on your HP box then you don't even need to install the Net::FTP module from www.perl.org/CPAN because it's already on your box. You can put your login/passwd in the script OR setup a .netrc file to do it automatically.

The attached example cd to /tmp and starts transferring files listed on the command line.
The best feature of this Perl method is that error checking is very, very easy.

The attached script would be used like this:
ftpput.pl file1 file2 file3
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "All OK"
else
echo "Bad ${STAT}
fi

It will also automatically retry failed fails but you can easil;y modify it to suit your needs.

NOTE: Perl is not needed on the AS400 box for this to work.




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