Solved

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

Posted on 2001-07-17
8
761 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
 
LVL 5

Expert Comment

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

http://www.columbia.edu/kermit/ftpscripts.html
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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 20

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Strange date stored 22 100
Best tools for Backup and restore of Wordpress site 6 53
fizzArray2 challenge 1 60
mapAB Challlenge 35 88
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now