SUMMARY: script to ftp files

From: Andy Cohen <Andy.Cohen_at_cognex.com>
Date: Tue, 03 Apr 2001 12:53:28 -0400

Many thanks to everybody who replied -- 30 in less than 1 hour! And all of
them helpful!

There were basically two types of responses: suggestions on how to get fix
the script and suggestions on alternative products to use.

How to fix the script:
-------------------------
The critical piece I was missing was:

        to stuff all those commands into a 'here' document, like:

        ftp hostname <<EOF
        do ftp commands here
        EOF

and to put the login commands like this:

        user {username} {password}

which I did:

ftp -nvi {sunbox}.cognex.com <<EOF
user {username} {password}
{ftp commands ...}
bye

And now it's working great!

Alternatives to ftp:
----------------------
To script an interactive process you should use expect
(http://expect.nist.gov/)

and

  In any case, the past few years when I've had to automate file xfers
transfers I've either used scp instead, or written a script
using the Net::FTP package in Perl.

  I've found the Net::FTP package to be extremely simple, and much
more flexible since you can "mix and match" your FTP commands with
your Perl code and handle errors a whole lot easier. Of course, you can
find this Perl module at http://www.cpan.org, the excellent Perl
archive.

  I know this doesn't really help your current problem, but once you
discover the Net::FTP module I bet you'll never go back to shell scripting
FTP xfers... :^)

and

The /usr/bin/ftp client is not suitable for scripting. Forget about it.

If you must use the ftp protocol for this, at least use a smarter client
(like lftp, ftp://ftp.yars.free.net/pub/software/unix/net/ftp/client/lftp/;
or roll your own perl script based on the Net::FTP module).

My tool of choice, though, would be rsync (http://rsync.samba.org/).
Particularly if the files are large and changes to them are incremental.
You get a choice of rsh or ssh as the underlying transport mechanism.
I use rsync as part of a nightly cron script to refresh a backup copy of
about 250GB worth of data files on various hosts.

and

I'd use ncftp, which you can script from the command line, as in
ftp -get|put host:/path/to/file.
Check out www.ncftp.com

and

and of course there's rcp -- no passwords to send over network.


Additional shell fix suggestions:
--------------------------------------

several people suggested putting the ftp commands into another file an using
that as input to the ftp command such as:

I always put the ftp commands in a file and then assign that to stdin, eg:

in file work.ftp:

cd wherever
ascii
put file.dat
exit

in the shell:

ftp {servername} < work.ftp

and I put the relevant username/password in .netrc, sometimes dynamically
where there's a security issue


Final note:
------------
if anybody wants to use the .netrc file you should know that it goes on the
client side of the ftp (the box you're running the script from) not the box
you are trying to connect to with ftp. I had the .netrc file on the wrong
machine.


Thanks again everbody!
Andy


Original posting:
-------------------
Hi,

I'm trying to write a script to ftp files from an alphaserver to a sun box
that will run periodically through cron. I thought this would be easy but I
just can't get it to work. I've just about memorized the ftp man page.

Here's basically what I've tried:

echo starting ftp
ftp {sun_box}
{username}
{password}
{other ftp commands}
bye

I get errors in the log file along these lines:

starting ftp
+ ftp -ivt {sun_box}
Connected to {sun_box}.cognex.com.
220 {sun_box} FTP server (SunOS 4.1) ready.
Name (nova:oracle): 331 Password required.
530 Login incorrect.
Login failed.
221 Goodbye.
+ {username}
+ echo finished ftp
finished ftp

I tried putting all the commands into a .netrc file in $HOME on the Sun box.

What am I missing? Does anybody have a script that does this that they can
share with me? I've tried modifying the commands in all sorts of different
way all to no avail. I must be doing something incorrectly or leaving
something out.

Thanks!
Andy
Received on Tue Apr 03 2001 - 16:54:44 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:42 NZDT