1833870 Members
1533 Online
110063 Solutions
New Discussion

FTP SCRIPT

 
SOLVED
Go to solution
VIJAY KUMAR_8
Occasional Contributor

FTP SCRIPT

I need to copy folder from remote machine to local machine using FTP. How to write a batch file to automate FTP commands. If anyone can help me in writing this batch file
8 REPLIES 8
RAC_1
Honored Contributor

Re: FTP SCRIPT

(
echo "echo "user user_name user_pass"
echo "bin"
echo "cd /to_dir"
echo "put your_file"
echo "close"
echo "bye"
)|ftp -vni hostname > log_file


AND

ftp -in myhost << EOF
user username password
get /tmp/bla
get /tmp/foo
EOF


Not good as it exposes the password. Use scp instead.
There is no substitute to HARDWORK
Antonio Cardoso_1
Trusted Contributor
Solution

Re: FTP SCRIPT

here an example that would do the job, just change username, password and local path to your own values, then call

ftpbatch your-ftp-host file1 file2

-----------------------------
#!/bin/sh
#?-----------------------------------------------------------
#? ftpbatch utility
#?
#? Syntax:
#? ftpbatch [#?-----------------------------------------------------------
if [ $# -lt 2 ]
then
grep '#?' $0 | grep -v grep | tr -d "#?"
exit 1
fi
THEHOST=$1
username=userx
userpw=ftppwd
localpath=/tmp

shift
NBPARAM=$#
FICTMP="/tmp/MFTPTMP.tmp.$$"
umask 077
#
echo "user root omccn1" >$FICTMP
echo "binary" >>$FICTMP
echo "lcd $localpath" >>$FICTMP
I=`expr 0`
while [ $I -lt $NBPARAM ];do
destfile=`basename $1`
echo "get $1 $destfile " >>$FICTMP
echo "site chmod 777 $destfile" >>$FICTMP
I=`expr $I + 1`
shift 1
done
echo "quit" >>$FICTMP
#
ftp -inv $THEHOST < $FICTMP
rm $FICTMP
exit 0
Muthukumar_5
Honored Contributor

Re: FTP SCRIPT

strange...... I was replying in another thread.. but it was removed.

Solution:

ftp -in <<-!
user
commands
bye
!

will work.

--
Muthu
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: FTP SCRIPT

You can as well avoid the user command in ftp to show the password using .netrc file setup in your users home directory.

Read netrc man page for example setup. Then use ftp script without user command.

--
Muthu
Easy to suggest when don't know about the problem!
Peter Godron
Honored Contributor

Re: FTP SCRIPT

Vijay,
I am not sure whether by 'folder' you mean a file or directory.

For individual file transfer see earlier answers.

For copying directory structure, seem the various packages at:
http://hpux.connect.org.uk/hppd/hpux/Networking/FTP/

Other solutions would be to use rcp or nfs.
Arunvijai_4
Honored Contributor

Re: FTP SCRIPT

Hi Vijay,

You can take a look these threads for more information,

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=973452
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=129038

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
VIJAY KUMAR_8
Occasional Contributor

Re: FTP SCRIPT

Thanks to u all
:-)
Arunvijai_4
Honored Contributor

Re: FTP SCRIPT

Vijay, You can close this thread.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"