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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

-- Need some serious help regarding FTP script --

Status
Not open for further replies.

r9ronaldo

Programmer
Jun 19, 2003
28
US
As a part of my task I have to ftp a file from one unix server onto the another UNIX server, I was able to do it inte ractively,
I jsut thought of coming up with a script, after some dragging the feet I wrote this script, But when I run this, it kind of
just hangs up and does nothing, I honestly don't know where this script is going wrong,

Any help is highly appreciated,
Cheers

The script is below
#!/bin/ksh
##################################
FTP_HOST='abc.xyz.com'
FTP_LOGIN='user'
FTP_PASSWD='passwd'
COMMAND='put'
LOCAL_DIR='/data_dir/source'
REMOTE_DIR='/prod_data_dir/target'
##########################################
ftp -inv $FTP_HOST <<END_SCRIPT
quote USER $FTP_LOGIN
quote PASS $FTP_PASSWD
$COMMAND $LOCAL_DIR/test.dat $REMOTE_DIR/test.dat
quit
END_SCRIPT
exit 0

Best regards

r9ronaldo

Forza Inter
 
Get rid of the quit and replace with bye. Also get rid of the END_SCRIPT line.
 
comtec17, while you were at it you could've suggested getting rid of the script it self [wink]

substitute:

quote USER $FTP_LOGIN
quote PASS $FTP_PASSWD

WITH:

USER $FTP_LOGIN $FTP_PASSWD

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi,
This syntax will work

.... your VARIABLES setting ...
...
ftp -inv $FTP_HOST <<END_SCRIPT
user $FTP_LOGIN $FTP_PASSWD
$COMMAND $LOCAL_DIR/test.dat $REMOTE_DIR/test.dat
quit
END_SCRIPT
exit 0


Ali
 
Here is a skeleton I use for creating FTP batch jobs. It is designed for AIX, but should be fairly portable.

#!/bin/ksh
bindir="/home/ftp/bin"
logdir="/home/ftp/log"
ftp="/usr/bin/ftp"
Email="root"
IP="10.x.x.x"
user=""
pass=""
ifile=""
ofile=""
type="asc"
myname=`basename $0`
verbose="verbose"
dd=`date +%d`
log="$logdir/$myname.$dd.log"
host=`hostname`
rc=0
boj=`date`

exec 1>$log 2>&1

echo "\n##### Begin FTP Parameters #####\n"
echo "Program Name: $myname"
echo "Process ID: $$"
echo "Log file name: $log"
echo "Email: $Email"
echo "Source Machine $host"
echo "Destination Machine: $IP"
echo "User ID: $user"
echo "Password: ##############"
echo "Source File: $ifile"
echo "Destination File: $ofile"
echo "\n##### End FTP Parameters #####\n\n"

echo "##### Begin FTP Session #####\n"

echo "open $IP
user $user $pass
$verbose
$type
put $ifile $ofile
close
quit" |$ftp -n

echo "\n##### End FTP Session #####"

foo=`grep -i "cannot" $log`
if [ "$?" -eq "0" ] ; then
rc=1
status="Destination file does not exist\n"
fi
foo=`grep -i "does not" $log`
if [ "$?" -eq "0" ] ; then
rc=1
status="${status}Source file does not exist\n"
fi
foo=`grep -i "killed" $log`
if [ "$?" -eq "0" ] ; then
rc=1
status="${status}File transfer process has abended\n"
fi
foo=`grep -i "space" $log`
if [ "$?" -eq "0" ] ; then
rc=1
status="${status}Ran out of disk space before completion of copy\n"
fi
foo=`grep -i "netout: write returned 0" $log`
if [ "$?" -eq "0" ] ; then
rc=1
status="${status}One or more files transfered were ZERO bytes in size or empty"
fi
foo=`grep -i "not connected" $log`
if [ "$?" -eq "0" ] ; then
rc=1
status="${status}Error connecting to server\n"
fi
foo=`grep -i "Access is denied" $log`
if [ "$?" -eq "0" ] ; then
rc=1
status="${status}File or directory permission error\n"
fi

if [ "$rc" -eq "0" ] ; then
status="Successful"
fi

eoj=`date`
echo "\nJob start time: $boj"
echo "Job end time: $eoj"
echo "\nResult code: $rc ($status)\n"

mail -s "FTP results from $myname" $Email <$log
 
Thank You all for your response,

I did try what vgersh99 and Ali suggested, Unfortunately when I tried to run the script in the backgroud after making the changes suggested using
nohup ftp.ksh 1>$HOME/log/ftp.log 2>&1 &
It created a numerous sub processes being created for every second, I guess the script went into infinite loop
, I ran the risk of bringing down the Unix box, So I had to abort it.
I am not sure what in the script caused it to go into infinite loop, and create all those sub processes.

Here is the script I used

#!/bin/ksh
##################################
All variable declarations
##########################################
ftp -n $FTP_HOST<<END_SCRIPT
user $FTP_LOGIN $FTP_PASSWD
$COMMAND $LOCAL_DIR/test.dat $REMOTE_DIR/test.dat
quit
END_SCRIPT
exit 0
###############################################

Thank You once again

r9ronaldo
 
All variable declarations
Have you defined FTP_HOST, FTP_LOGIN, FTP_PASSWD, COMMAND, LOCAL_DIR and REMOTE_DIR ?
Either in this script or prior the launch (and then are they exported ?).

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
I have defined the Variables in the script

Thank You

R9ronaldo
 
Thank You One and all,

I got it to working.

Thanks Again

R9ronaldo

Forza Inter
Forza Neraazzuri
 
r9ronaldo, thanks for sharing.
Can you please explain the members how you got it to working ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Hi,

Here is the script I use every day for this purpose
VARIABLES setting ...
...
FTPLOG="/tmp/$(basename $FILE).ftp.log"
date >> $FTPLOG
# Connexion FTP et transfert du fichier $FILE
ftp -i -n -v $TARGET_IP <<-!EOFTP |tee -a $FTPLOG 2>&1
user $FTP_LOGIN $FTP_PASSWD
cd $TRAGET_DIRECTORY
pwd
lcd $SOURCE_DIRECTORY
binary
send $FILE
quit
!EOFTP

cd : changes directory in the target machine
lcd : changes directory in local machine
binary : to send data in bin mode

Ali

 
Hi all,

Thanks for all your responses, Here is the script I used,

#!/bin/ksh
##################################
FTP_HOST='user.xyz.com'
FTP_LOGIN='user'
FTP_PASSWD='passwd'
COMMAND='put'
LOCAL_DIR='source/data'
REMOTE_DIR='target/data'
FTP_FUNCTION='/usr/bin/ftp'
##########################################
$FTP_FUNCTION -n $FTP_HOST <<END_SCRIPT
quote USER $FTP_LOGIN
quote PASS $FTP_PASSWD
$COMMAND $LOCAL_DIR/test.dat $REMOTE_DIR/test.dat
quit
END_SCRIPT
exit 0
#############################################
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top