Operating System - HP-UX
1825803 Members
2700 Online
109687 Solutions
New Discussion

Re: scripts for ftp uploading and downloading

 
Ricky_4
Frequent Advisor

scripts for ftp uploading and downloading

Hi All,

Please help us how to create scripts for ftp downloading and uploading so I can automate this during off peak hours.

Thanks.
5 REPLIES 5
Volker Borowski
Honored Contributor

Re: scripts for ftp uploading and downloading

Hi Bal,

this is fairly simple:

Have commands.ftp like

cd /remote_sourcedir
lcd /local_targetdir
asc
get file_to_download
bye

Set up .netrc for the OS-user to use this interface.

execute

cat commands.ftp | ftp targethost

That is all
Volker
Sridhar Bhaskarla
Honored Contributor

Re: scripts for ftp uploading and downloading

There isn't much difference between uploading and downloading except replace put with get.

ftp -i -n -v << EOF
open your_sytem
user your_user_name your_passwd
cd your_dir
prompt off
mput * (or put your_file)
bye

EOF


You can also use netrc if you don't want to include your user name and password in this script. But you have to - somewhere.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Santosh Nair_1
Honored Contributor

Re: scripts for ftp uploading and downloading

It would probably be easier setting up rhosts/host.equiv and do an rcp or rdist, if that's an option. You could also use scp if security is a big concern.

-Santosh
Life is what's happening while you're busy making other plans
Ralph Grothe
Honored Contributor

Re: scripts for ftp uploading and downloading

I would agree to what Santosh posted.

Nowadays where there is strong encryption and ssh available one should deprecate the use of the r* commands, telnet, and ftp.
Best remove their service from inetd.conf.

Only if you are using them in a firewalled, trusted host environment are they acceptable.

If you still insist on ftp read the manpages of ftp, and netrc.
It's all described therein.

If you like Perl it's much less a pain in the a* to use the CPAN modules Net::Ftp, Net::Telnet, Net::Expect, or better Net::SSH::Perl.
Madness, thy name is system administration
Wodisch
Honored Contributor

Re: scripts for ftp uploading and downloading

Hello Bal,

why did you not "search" for this topic first?
There are already a lot of very good answers for it!

Well, the main point is, there are features built into ftp
for doing just that, so you do NOT need all that fuss
about input-redirection ;-)

On UN*X systems, you have to use the file
"$HOME/.netrc"

and on Windows systems (client-wise speaking) there
is an command-line option for it.

UN*X:
Your "$HOME/.netrc" would have permissions 600 and
look like this (replace UPPERCASE with your own values):

machine SERVER login USER password SECRET macdef init
cd /remote-dir
lcd /local-dir
prompt
binary
mput *.*
quit

There should be an empty line at the end of that
paragraph.

On Windows you have the option "-s:" to pass a textfile
containing the username, password , and commands,
where the the first line contains the username, the
second contains the passwords, and the rest of the file
contains the commands, just like on UN*X.

HTH,
Wodisch