1829601 Members
2026 Online
109992 Solutions
New Discussion

automatic FTP script

 
SOLVED
Go to solution
tayal_sumit
Occasional Advisor

automatic FTP script

Hi all,

I am doing FTP with a shell script but it is not running properly.Please send me if anybody have any automatic ftp script.

#!/usr/sbin/sh
ftp -i -n 10.1.1.76
user (username)/(password)
bin
cd /home/user home dir
lcd /home/dir
mget *.txt
bye

regards,
4 REPLIES 4
Bill Hassell
Honored Contributor
Solution

Re: automatic FTP script

You got everything correct except the 'here document' codes. The commands below the ftp line must be flagged as belonging to ftp's STDIN and this is done with << plus an ending string such as EOF. This should work OK:

#!/usr/sbin/sh

USER=bill
PW=abc123
ftp -v -i -n 10.1.1.76 << EOF
user $USER $PW
bin
cd /home/$USER
lcd /home/$USER
mget *.txt
bye
EOF

The << EOF string says: take the following lines and feed them into ftp, then stop when EOF is found.


Bill Hassell, sysadmin
James R. Ferguson
Acclaimed Contributor

Re: automatic FTP script

Hi:

This will not work. One way using this technique is:

{ echo "open 10.1.1.76
user theuser thepassword
type binary
cd /home/userhomedir
lcd /home/dir
mget *.txt
bye"
} | ftp -in

A more secure way than putting an account password into a script (although still not the most secure way) is to use the '.netrc' file. See the manpages for 'netrc(4)'.

Regards!

...JRF...
Steven Schweda
Honored Contributor

Re: automatic FTP script

cd /home/dir
wget "ftp://${user}:${pass}@10.1.1.76/home/user_home_dir/*.txt"


http://www.gnu.org/software/wget/wget.html
tayal_sumit
Occasional Advisor

Re: automatic FTP script

Hi Bill,

I have tried your script it's working nice.

Keep up the good work.

Thank you very much

regards,
Sumit