FTP return value


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users FTP return value
# 1  
Old 06-03-2003
FTP return value

Hi guys,
I am having a problem to determine if the FTP request I had was successful or not... Here is what I do:
In a shell script I call another shell script to do the FTP like:
Code:
#!/bin/ksh
echo "Hello..."
...
# call do_ftp.sh
do_ftp.sh $SERVER $USR $PASS $FILE....

status=$?
if [ status -ne 0 ]; then
  echo "FTP error"
else
  echo "FTP OK"
fi

and do_ftp.sh is like below:
Code:
exec 4>&1
ftp -inv >&4 2>&4 |&

print -p open $FTPSERVER
print -p user $USER $PASSWD
print -p lcd $OUTPUTDIR
print -p binary
print -p put $ZIPFILE 
print -p quit

but even if I pass wrong parameters, status would always be equal 0.
I've tried using inline redirection or "value=do_ftp.sh ..."
and so and so but I am not getting anywhere...

I'd appreciate any help...

added code tags for readability --oombera

Last edited by oombera; 02-20-2004 at 05:25 PM..
# 2  
Old 06-03-2003
I had the same sort of issue. For FTP, I used a function within the script (matter of preference I guess) The program was dependant upon a file that was retrieved nightly from an FTP server. Instead of trying to resolve the correct return code from FTP, I focused
on evaluating the result of the FTP - the file itself. If it
was there, then everything was cool. If not, well, fail. I also checked for an empty file and exited if it was.

just noticed your doing a "put" and not a "get"...oh well...maybe this will still spark an idea or two.
Code:
ftp_func () {
ftp -v -n $TO_HOST << ENDFTP
user $USERNAME $PASSWORD
ascii
prompt off
hash on
lcd $FILE_DIR
get $INPUT_FILE_NAME
bye
ENDFTP
}
if [ ! -r $FILE_DIR/$INPUT_FILE_NAME  ]			 
	      then
	         echo "ERROR-APP-->: FTP Process Has Failed or FTP Server Unavailable." | tee -a $INLOG
		 	   else
	       echo "INFO-->: FTP Process Completed Successfully!" >> $INLOG
		           fi
test -s $FILE_DIR/$INPUT_FILE_NAME

FILE_TEST=$?

if [ $FILE_TEST -gt 0 ]
   then
      echo "INFO-->: $INPUT_FILE_NAME Is An Empty File. Skipping SQL*LOADER Process!" | tee -a $INLOG
      echo "INFO-->: FTP Completed Successfully" >> $INLOG
exit $SUCCESS
   else
      echo "INFO-->: Completed File Check - Starting SQL*LOADER Process." | tee -a $INLOG
fi

added code tags for readability --oombera

Last edited by oombera; 02-20-2004 at 05:25 PM..
# 3  
Old 06-03-2003
Hi google,
Thanks for the reply...
The reason I'm using a different shell script (not the function) is because it gets called by number of other scripts...
Unfortunately I am sending the files across to other servers and no get! so I don't know how find out if I had a successful transfer...

Thanks again for your comment...
# 4  
Old 06-05-2003
One thing you might do is log the FTP event.

do_ftp.sh Param1 Param2 param3 param4


ftp -v -n $1 << ENDFTP > /tmp/do_ftp_report_$4.log
user $2 $3
ascii
prompt off
put $$4
bye
ENDFTP

then have your calling script(s) examine the log file created searching for specific keywords to indicate success or failure. In binary mode you can also test the bytes sent line against the original size of file, track transfer time statistics. etc.

Hope it helps.
# 5  
Old 06-05-2003
To see if a file exists on a remote ftp server, use the ftp program in a script and do this command:
dir file.in.question local.out

You will need to turn off interactive mode before you do that command. After the ftp job finishes, look at the file local.out. If the remote file did not exist local.out will be empty. Otherwise it will have some contents.
# 6  
Old 06-11-2003
Thanks Perderabo it was a very helpful tip...

You know what's the problem now?

At the end of FTP process I "dir" the remote file on a local file like below:
....

exec 4>&1
ftp -inv >&4 2>&4 |&

print -p open $FTPSERVER
print -p user $USER $PASSWD
print -p lcd $OUTPUTDIR
print -p binary
print -p put $ZIPFILE
print -p dir $ZIPFILE local.out
print -p quit

....
but this file is not available for the first script which called do_ftp.sh

if [ -s $OUTPUTDIR/local.out ]; then
"Yes"
else
"No"
fi

It always says No... But file is there and I can test it (-s) through another scripts... It's weird... I think it might be related to the open pipe!
exec 4>&1
ftp -inv >&4 2>&4 |&

Have you came across this iussue before?
# 7  
Old 06-11-2003
After the "print -p quit" line, you need to have a line that just says "wait".

You are spitting lines at your ftp client very fast. That's the equivalent of typing ahead. You need to let the ftp job finish. The wait command will reap the zombie that results when the ftp job finishes. At that point the file will exist.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to capture 3 digit return code of ftp??

is it possible to capture the 3 digit return code of ftp commands in a local variable inside a shell script? Code: ftp remoteserver << EOFTP quote USER uid quote PASS pass prompt cd remote_directory mput file.txt bye EOFTP in the above script, if cd ... (4 Replies)
Discussion started by: Little
4 Replies

2. Shell Programming and Scripting

Return Value from a FTP shell script

Hello folks,,, I am calling a Unix shell script from java. The unix script is transferring a file through FTP. I wonder how can I confirm whether the script has been executed properly without any error. Is there any way to find the return value from the script. My FTP script is given below ... (3 Replies)
Discussion started by: dinesh1985
3 Replies

3. UNIX Desktop Questions & Answers

ftp return code not working

below is my code , but for some reason the return part is not working, only file transfer is happening and no exit status is checked .please me help me to fix this code #!/bin/sh #set -vx ftp -nv sitelocation << ! user username password lcd localdir cd /remote dir mget *.* ... (4 Replies)
Discussion started by: gwrm
4 Replies

4. Shell Programming and Scripting

Return all sub directories on ftp server

Hey guys, I'm new to the programming world in general, and I only write in applescript so far. I am trying to find a shell script that will return a list of all the sub directories (or folders) within a directory on my ftp server. The server needs a username and password. I would assume the... (4 Replies)
Discussion started by: thriftinkid
4 Replies

5. Shell Programming and Scripting

No return code in ftp mget script

I have a automated FTP script that gets a file using mget. I am using mget because the date will change on the file frequently. The mget works, however if I incorrectly type the file (e.g. if I want to get /dog123 and I enter /dg*) I do not receive and error code from in the FTP session. The... (1 Reply)
Discussion started by: dog123
1 Replies

6. IP Networking

FTP Return 32

Dear All, I have problem when uploading files the FTP Server threw message like this : ftp return 32. Files not get uploaded. OS is Sun Soalaris 2.10 Please help what is the meaning of that message... Thanks (3 Replies)
Discussion started by: wilsonSurya
3 Replies

7. UNIX for Dummies Questions & Answers

FTP Return Code

Hi All, I have a problem to identify the error code thrown by FTP Server while uploading files. The message is : ftp return 32. I couldn't find out what is the meaning of that. :confused: OS is Sun Solaris 2.10. Anyone can help? Thanks a lot (1 Reply)
Discussion started by: wilsonSurya
1 Replies

8. Shell Programming and Scripting

capture ftp return code..PLZ HELP

Hi all, i have written a code to ftp a file from one server to other.The ftp is happeneing successfully,but i am not able to capture the return code,to check if ftp has failed. plz help me to find out the return code....this is urgent below is the code i have written... (3 Replies)
Discussion started by: anju
3 Replies

9. Shell Programming and Scripting

return ftp status

Hello, I still have problems when trying to figure out if the status of an ftp was successful. I ftp to different types (nt, vax, unix, etc...) of machines. I am trying to write a universal script that will ftp a file and then check to see if the ftp was successful. I have tried the... (12 Replies)
Discussion started by: blt123
12 Replies

10. UNIX for Advanced & Expert Users

return code on ftp if filesystem full??

Does anyone know what the return code will be if an ftp fails because the /var/tmp filesystem is full? AIX 4.3 (1 Reply)
Discussion started by: lawadm1
1 Replies
Login or Register to Ask a Question