Operating System - HP-UX
1843944 Members
2468 Online
110226 Solutions
New Discussion

ftp scripting (?) question

 
SOLVED
Go to solution
Vogra
Regular Advisor

ftp scripting (?) question

Hi All!

I need to send files from unix to windows 2000 ftp server.
I use the following comands:
ftp
open
anonymous
email@domain.com
mput *.ema
y

But I need to send a lot of files and I want to automate it. Help me!
Lima.
We are spirits in the material world
7 REPLIES 7
harry d brown jr
Honored Contributor
Solution

Re: ftp scripting (?) question


Won't happen unless your windoze box has an ftp daemon process running.

You can frp FROM your windoze box to GET the file.

If you DO have an ftp enabled windoze box, then on the unix system have a script like this:

...
/usr/bin/ftp -i -n WINDOZEbox.com << EOF
user "anonymous" "SOMEemailaddr"
bin
mput *.ema
EOF


live free or die
harry d brown jr
Live Free or Die
renarios
Trusted Contributor

Re: ftp scripting (?) question

Hi Lima,
There are two methods:
First is to install the latest version of WS-ftp on your windows-can. That way you can schedule ftp transfers.
Second is to create a tarball of all the files you need and ftp the tar-ball to your windows-can.
On windows you can untar i.e. by using winzip from the command-line in a batch script

Cheers,

Renarios
Nothing is more successfull as failure
Peter Godron
Honored Contributor

Re: ftp scripting (?) question

Vogra,
you also want the "prompt" command prior to the mget, to avoid being asked to confirm each file.
Regards
Jan Sladky
Trusted Contributor

Re: ftp scripting (?) question

Hi Vogra,

try this

usr/bin/ftp -i -n -v < /dir/ftp_connect.txt

cat ftp_connect.txt

open 10.32.113.177
user anonymous qq@qq.com
bin
hash
prompt off
cd dir
mput *.ema
bye


rgds Jan

GSM, Intelligent Networks, UNIX
Sergejs Svitnevs
Honored Contributor

Re: ftp scripting (?) question

Expect can help you to automate ftp applications.

#!/usr/bin/expect -f
#
spawn ftp
expect "Name"
send "anonymous\r"
expect "Password:"
send "email@domain.com\r"
expect "ftp>"
send "binary\r"
expect "ftp>"
send "mput *.ema\r"
expect "mput"
send "y\r"
expect "ftp>"
send "exit\r"
exit


Regards,
Sergejs
Steven E. Protter
Exalted Contributor

Re: ftp scripting (?) question

Theft and mod on Harry's concept below

# Make a file list.
ls -1 /tmp/filelist

while read -r filename
do

/usr/bin/ftp -i -n WINDOZEbox.com << EOF
user "anonymous" "SOMEemailaddr"
bin
put $filename


done < /tmp/filelist

This way is pretty flexible, but it does fire up the ftp process for every file transfer. It does insure there will be no accidental user interaction.

SEP
EOF
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Richard Hood
Advisor

Re: ftp scripting (?) question

I would use the below script to create a /.netrc file on the fly and then each time I needed to send the file to the site all I have to do is make a call to ftp to that site. (ie: ftp ftp_site)

I have made some generic references to host/vendor names and such but the script builds the .netrc file on the fly with the appropriate entries to put multiople files to that server.

Richard

#!/usr/bin/sh
#

create_netrc() {
ROUTINE="::create_netrc:"
cat > $HOME/.netrc<machine ${VENDOR_FTP}
login ${FTP_LOGIN}
password ${FTP_PASSWD}
macdef init
ha
as
prompt
verbose
lcd ${DIR}
mput ${FILENAME}
bye


EOF
check_error
}

get_file() {
ROUTINE="::get_file:"
ftp -g ${VENDOR_FTP} >$OFILE 2>&1
check_error
}


move_file() {
cd ${DIR}
mv * archive >$OFILE 2>&1
check_error
}

check_error() {
STATUS=`echo $?`
if [ ${STATUS} != 0 ]
then
mailx -s"`hostname`: ${VENDOR} Download Failed" ${MAILBOX} <
The following ERROR CONDITION occured during $ROUTINE: $STATUS

The above error code resulted in the following error message:

*** `cat $OFILE`
EOF

exit $STATUS
fi
}

if [ -r /.netrc ]
then
rm /.netrc
fi
FTP_LOGIN="anonymous"
FTP_PASSWD="root"
MAILBOX="root"
VENDOR="ftp"
VENDOR_FTP="ftp_ftp"
OFILE="/tmp/${VENDOR}_output"
DIR="/mnt/transfer/${VENDOR}"
DATE=`date +%m%d%Y`
FILENAME="PS_${DATE}"
create_netrc
chmod 0600 /.netrc
get_file
move_file
If it ain't broke - Don't fix it