Operating System - HP-UX
1833784 Members
2128 Online
110063 Solutions
New Discussion

Need help on writing a script to run ftp...

 
SOLVED
Go to solution
Jessica Chou
Advisor

Need help on writing a script to run ftp...

Hi!
How do I run a script to ftp a site
and mget files? (assume that I am sure where
the files be). Something as below does not work.

ftp 192.168.0.1
username1
hispass
prompt
mget *.dat
bye

unquote *****
It stopped at the prompt for asking user name.

Thank you for your help.

Jessica

4 REPLIES 4
federico_3
Honored Contributor

Re: Need help on writing a script to run ftp...




Create a file called .netrc in the home directory of the user who gets the files.
set the permissions as 700 .
Add the following lines in this file:
*********************************
machine
login
password
prompt
mget *.dat
bye

******************************
Note: this file needs 1 blanck line after the bye statement.

After you make .netrc file, then enter:

# ftp 192.168.0.1

I hope this helps,
federico



Andreas Voss
Honored Contributor

Re: Need help on writing a script to run ftp...

Hi,

you could do:

ftp -n <open 192.168.0.1
user username1 hispass
prompt
mget *.dat
bye
EOF

Regards
Tommy Palo
Trusted Contributor
Solution

Re: Need help on writing a script to run ftp...

$HOME/.netrc:
---------------------
machine
login
password
macdef init
verbose
cd
mget *.dat
bye
<-- Blank Line
---------------------

$ ftp -i HOST
Keep it simple
Ossie de Jongh
Advisor

Re: Need help on writing a script to run ftp...

This will work if you want to automate things:
put the following in a script:

/usr/bin/ftp -vin <open hostname_here
user "username" "passwd" #without the qoutes
binary
#cd to directory if needed
#lcd to local directory if needed
mget *
quit
EOF

the -v is important, else the script will hang on a prompt y/n