Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP UNIX Script 2

Status
Not open for further replies.
May 23, 2002
8
US
Does anyone have a good example of a script that is using FTP to transfer a file to another server ? This script will be running as a CRON job and sending the file daily to one of our central servers. Any help is appreciated....
 
#!/bin/ksh

# ftp server/login info
FTP_HOST=some.host.name
FTP_USER=user_name
FTP_PASSWD=password

# local directory
LOCAL_DIR=

# remote directory
REMOTE_DIR=/prod/int/home/intranet/employee_survey

# file
XMT_FILE=

# command
COMMAND=get #put or get

ftp -n $FTP_HOST<<END_SCRIPT
quote USER $FTP_USER
quote PASS $FTP_PASSWD
$COMMAND $LOCAL_DIR/$XMT_FILE $REMOTE_DIR/$XMT_FILE
quit
END_SCRIPT
Robert G. Jordan
Unix Sys Admin
Sleepy Hollow, Illinois U.S.A.
sh.gif


FREE Unix Scripts
 
I'm using the Bourne Shell, will the script change that much since you are using the KSH ?
 
Hi Robert, I was looking over your example unix script as I'm also in need of an example. I need to ftp a data file from a nt server thats running mks toolkit v7.5 which creates a shell environment.

Here's my ftp code so far from my unix script....

cd $XFR_HOME
FTP -n servername<<END_SCRIPT
quote USER abcd
quote PASS abcd
$put file.dat
quit
END_SCRIPT
cd $DW_HOME

The code above executes but somewhere fails. We can do the same steps maunally and it work ok.

Any help would be appraciated!!
much thanks
Richard
 
I noticed you have have a &quot;$&quot; sign in front
of your put command.

a dollar sign denotes a variable

try removing the dollar sign.
Robert G. Jordan
Unix Sys Admin
Sleepy Hollow, Illinois U.S.A.
sh.gif


FREE Unix Scripts
 
These posts have been very helpful for some scripts I'm trying to write myself -- thank you to everyone who's posted so far.

I've got a trickier question, though. In my script, I need to do an FTP push (as outlined above), but then invoke another script afterwards that is dependent on the FTP transmission having been successful. Does anyone know of a good way of verifying that the FTP transmission was successful within the script itself? For example, if my FTP account is locked out, I'd like to be able to trap the error there before continuing on in my script. I've considered redirecting the output of the FTP session to a file and then grepping for various keywords that would indicate FTP problems, but I was wondering if anyone new of any nicer/cleaner ways to do this kind of error checking.

Any thoughts would be appreciated!!
-- Daryl
 
Robert,
what if I wanted to ftp multiple files in multiple directories.. how could I do this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top