* ftp scripts
@ 1998-09-21 4:00 Al
1998-09-22 4:00 ` Roy Olsen
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Al @ 1998-09-21 4:00 UTC (permalink / raw)
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?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: ftp scripts
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
2 siblings, 0 replies; 5+ messages in thread
From: Rolf Hauck @ 1998-09-22 4:00 UTC (permalink / raw)
To: Al
I prefer to do those things with something similar to
(
echo "open host"
echo "put fileA"
echo "put fileB"
echo "quit"
) | ftp
Rolf
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?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: ftp scripts
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
2 siblings, 0 replies; 5+ messages in thread
From: Roy Olsen @ 1998-09-22 4:00 UTC (permalink / raw)
Here's one way to do it;
#!/bin/csh
set REMDEST="host"
set USER="user"
set PWD="password"
set REMFILE1="remote.file1"
set REMFILE2="remote.file2"
set LOCFILE1="local.file1"
set LOCFILE2="local.file2"
# Get files
ftp -n ${REMDEST} <<EOF
user ${USER} ${PWD}
get ${REMFILE1} ${LOCFILE1}
put ${LOCFILE2} ${REMFILE2}
quit
EOF
---
Roy Olsen
UNIX Team
Sema Group Norge
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: ftp scripts
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 ` another way Avarham Shapiro
2 siblings, 1 reply; 5+ messages in thread
From: Rob Urban @ 1998-09-29 4:00 UTC (permalink / raw)
I promise you you'll be happier in the long run if you get perl (there is a
setld perl kit on
ftp.digital.com:/pub/DEC/) and then get the ftp extension for perl and use
that. It allows you
to completely automate ftp transactions *reliably*.
Another solution is to get TCL/TK, and then build the expect extension, which
allows the automating
of arbitrary command-line dialogs.
Rob Urban
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?
^ permalink raw reply [flat|nested] 5+ messages in thread
* another way
1998-09-29 4:00 ` Rob Urban
@ 1998-10-05 4:00 ` Avarham Shapiro
0 siblings, 0 replies; 5+ messages in thread
From: Avarham Shapiro @ 1998-10-05 4:00 UTC (permalink / raw)
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?
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~1998-10-05 4:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` another way Avarham Shapiro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox