Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: Avarham Shapiro <Avarham.Shapiro@AmMobile.com>
Subject: another way
Date: 1998/10/05	[thread overview]
Message-ID: <56045E2FB5F0D1119E4F0000F863199D014B0B50@SY3026.AmMobile.com> (raw)
In-Reply-To: 36107E7D.8589ADBA@rto.dec.com


If you don't know TCL or PERL and you're pressed for time you can do
some relatively
easy  things:

1. Create a .netrc file.  If you connect to multiple hosts include all
of them
in it.  If the passwords or usernames change you must write it on the
fly from
your shell script before invoking ftp. Remember to have a protection of
400 (root read only)
on the .netrc (this does NOT mean that ftp must run under root).  The
.netrc resides in
home directory so there can be multiple instances.  The beauty of .netrc
is that it 
elimitates a need for an expect program.

2.  Run the shell which invokes ftp with the host name.  .netrc takes
care of login, open.

3.  either hardcode the ftp commands in the script or write them on the
fly.
This depends on whether you always get the same files

1. hardcode  example (in ksh):

FTP host-name << END
verbose off
debug on
binary
cd user
mget application_foo.*
quit
-END
if [[ $? -ne 0 ]]
then
  #handle the error
fi

2. Write on fly example

#compute file list (possibly the remote directory)
echo cd $user > /tmp/ftp.cmd
echo verbose off  >> /tmp/ftp.cmd
echo debug on >> /tmp/ftp.cmd
echo binary >> /tmp/ftp.cmd
echo mget $files-set >> /tmp/ftp.cmd
echo quit >>/tmp/ftp.cmd
FTP host-name </tmp/ftp.cmd
#
if [[ $? -ne 0 ]]
then
  #handle the error
fi

Note that when writing on the fly you can't separately send the 
dynamic part (like the get) from the inline part (like verbose off)
because once FTP is done reading stdin  or the here document which is
just an inline stdin there's an implicit quit and no opportunity to 
send the rest of the commands on the same connection. 

This method is admittedly  kludgy and somewhat convoluted.
But I have used it successfully where the process that determined what
files to send/receive had to write the redirection files on the
fly, kick off the shell,  monitor the health of  ftp (what if it hangs 
on a serial connection or drops it altogether) and process the files 
when the ftp shell was finished.  Remember that all the power of your
shell 
is available to you to help get it done fast or better stated -- quick
and dirty.

Good luck.



Al wrote:

> I am currently running a DUNIX 4.0b system. We have a requirement to
do
> some automated files transfers between ftp servers. I have written
script
> which uses some SQL to generate the file. I then need to ftp the file
to a
> remote site. I am having a problem with the syntax of my shell script.
How
> do you pass the relevant commands to ftp (open ftp.mycompany.com etc.)
from
> a shell script?




      reply	other threads:[~1998-10-05  4:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-09-21  4:00 ftp scripts Al
1998-09-22  4:00 ` Roy Olsen
1998-09-22  4:00 ` Rolf Hauck
1998-09-29  4:00 ` Rob Urban
1998-10-05  4:00   ` Avarham Shapiro [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox