Operating System - HP-UX
1834215 Members
2157 Online
110066 Solutions
New Discussion

how to run FTP through scripts ....

 
SOLVED
Go to solution
Bala_8
Frequent Advisor

how to run FTP through scripts ....

Hi i want to automate the ftp procedure through crontab entries ..... does any one did scripting to do this ?

I've a list of files and their corresponding locations on the host server .... every fortnight on week ends, i need to ftp those files to new locations in my remote client ....

In my network, the client can connect to the Host using ftp/telnet etc., but the host is protected by firewall to see the client ...

cheers
9 REPLIES 9
Scott Van Kalken
Esteemed Contributor

Re: how to run FTP through scripts ....

#!/bin/sh
set -x
ftp -i -n << !EOF
open 10.196.8.241
user anonymous scott@unix.com
cd /tmp
bin
put today.html
bye
!EOF



the set -x just reports the variables being set etc but it isn't required for real.

you can put any commands you like in here that you can use with ftp.

You could for example go:

prompt
mput *.txt


Hope this helps.

Scott.
Tom Geudens
Honored Contributor

Re: how to run FTP through scripts ....

Hi,
Another example

ftp -nv $dis_machine > /dev/null <
A life ? Cool ! Where can I download one of those from ?
Michael Tully
Honored Contributor

Re: how to run FTP through scripts ....

Hi,

You would need to open port 22 to let ftp traffic through. Not a good choice. You should perhaps look at using openssh with 'sftp'. It comes as part of the package. You can download the latest version (source) and compile it from http://openssh.org The current version from the porting centre has been identified as having a security hole.

The scripts that other guys have provided may in fact work with 'sftp'

Michael
Anyone for a Mutiny ?
Steven Sim Kok Leong
Honored Contributor

Re: how to run FTP through scripts ....

Hi,

As already mentioned, FTP is cleartext (i.e. data traffic can be sniffed on the network) and requires ftp-control (TCP/21) and ftp-data (TCP/20) to be opened at your firewall.

Apart from sftp as mentioned, you might also want to consider scp (the secured equivalent of rcp) and make use of public key trust relationships to automate file transfers securely. The ssh family provides security features of confidentiality, integrity and non-repudiation.

Hope this helps. Regards.

Steven Sim Kok Leong
Jeanine Kone
Trusted Contributor
Solution

Re: how to run FTP through scripts ....

Here is what I do:

My shell script which is run from cron has the following command (among other things)

ftp -n -v < cmdstosend > logfile 2>&1

The cmdtosend file has the following ftp commands in it:

open ip.address
user username password
cd "full_path"
pwd (just to echo for my log file)
lcd full_path
binary (or ascii)
put file
close quit

I then e-mail myself the log file for verification.
A. Clay Stephenson
Acclaimed Contributor

Re: how to run FTP through scripts ....

I'll give you my standard answer: Do this in Perl. You get error checking for free and that is a non-trivial exercise using other scripting approaches. The other nice thing is that the same script will run on NT.

I've attached an example script.

It first logs you in to a remote server, change the remote host, user, and password to suit your needs. It then does a cwd to /tmp and puts ftp in 'binary mode'. It then reads the command line for filenames to send. It will try each one up to 5 times. The beauty of doing this in perl is that the error checking is built right in. You will need to download and install the Net::FTP module from http://www.perl.org/CPAN but after that you are done. I never bother trying to do this stuff in the shell anymore because this is so much easier.

P.S. If you need to punch through a proxy server, simply supply a 3rd argument to the login subroutine and it will be just like you typed the account ftp command yourself.

Regards, Clay


If it ain't broke, I can fix that.
harry d brown jr
Honored Contributor

Re: how to run FTP through scripts ....


I agree with Clay. He's provided quite a few examples here on the forum and it's the only way I would go.

live free or die
harry
Live Free or Die
Wodisch_1
Honored Contributor

Re: how to run FTP through scripts ....

Hi Bala,

just like the rest I do not recommend "ftp" for this (and if you do use it anyway, please look at the "$HOME/.netrc" feature - "man netrc").
Investigate into tools like "scp" (part of SSH), or my favourite for this task "rsync" (using SSH for the transport).
See http://rsync.samba.org for details.
There are "rsync" clients for windows, too!

HTH,
Wodisch
Bala_8
Frequent Advisor

Re: how to run FTP through scripts ....

hi all,

thanks all for your valuable feedback ....
your replies solved my problem ....

thanks again

-bala-