Solved

How to get the return status of ftp command in UNIX KSH script?

Posted on 2001-07-17
8
806 Views
Last Modified: 2013-12-26
#!/bin/ksh
#Syntax to execute this script
#<programsName> icrt <path & from filename> <To path & FileName>


working_dir="/home/aclem01"

. $working_dir/.profile

# cd to work directory
cd $working_dir

# Which system to transfer to
if test $1 = "icrt"
then
                  ftp -in 101.215.181.180 <<ENDFTP
                  user <username> <password>
                  cd //home/aclem01
                  ascii
                  put $2 $3
                  quit
ENDFTP
          if [ $? -ne 0 ]
          then
              echo "$2 File is not transferd to $1"
              return 2
          fi
          echo "$2 File transferd to $1"
fi




when i execute this script,  "$?" always returns ZERO, even if the above ftp fails. How can get the return status of the ftp process inorder to print the success/failure message to the user?
Please some one help me.
0
Comment
Question by:mogunek
8 Comments
 
LVL 5

Expert Comment

by:marecs
ID: 6292756
the man page for ftp does not mention anyrthing about the exit status. Try this

ftp -inv 101.215.181.180 <<ENDFTP |grep '226 Transfer complete'

0
 

Author Comment

by:mogunek
ID: 6296391
I am unable to use like this, this is giving syntax error in the script.

Is there any other way to get the return status of get/put function within the ftp block.
Thanks,
0
 
LVL 3

Expert Comment

by:mrn060900
ID: 6317292
after the put,
do a get to a temporary dir and filename,
then do a test -s filename,
then rm the file from the temp dir

Not the best way, but a work around

Regards Mike

www.unixonline.co.uk
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:paulqna
ID: 6330346
I think this would be a better workaround...

http://www.columbia.edu/kermit/ftpscripts.html
0
 

Expert Comment

by:rajiv_indya
ID: 6333005
ANSWER:


if [ $? -ne 0 ]
this "$?" will give the status of "ftp" command which was successful , after that control goes to ftp.

Do this for solution :
before quit add following lines

lcd /temp
get $3

after ENDFTP add

if [ -f $3 ]
then
    echo "File transferd "
    rm $3
else
    echo "Error"
fi

0
 
LVL 4

Expert Comment

by:Otetelisanu
ID: 6348003
If is a error in the
ftp transfer (put or get) the error
is not in ($?) exit error.
Exit error is only 0.

1.Make ftp with debug.
2. Make a script when you compare
   the filebytes with ftp debug bytes

0
 
LVL 21

Expert Comment

by:tfewster
ID: 8191431
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:

- PAQ, no points refunded

Please leave any comments here within the next 7 days

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

tfewster
Cleanup Volunteer
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 8241138
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 134
Named range not carried over 10 66
fizzArray  challenge 1 109
java ^ examples 8 70
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question