The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to get the exit status yhacks Shell Programming and Scripting 1 05-19-2008 08:06 AM
exit status moxxx68 Shell Programming and Scripting 1 12-04-2004 07:27 PM
Checking the exit status of ftp psingh UNIX for Advanced & Expert Users 1 06-04-2002 10:51 PM
tar exit status thorndike UNIX for Dummies Questions & Answers 3 01-22-2002 04:39 PM
ftp exit status. oracle8 UNIX for Advanced & Expert Users 1 10-21-2001 11:34 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-11-2007
uni1234 uni1234 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 1
Exit Status of SFTP

I have a shell script which delivers the file to the SERVER B using SFTP.
I'm calling this script from java.
Now I need to find the exit status of the sftp, with the help of this I can find whether it was success or unsucess.

I'm using the variable "$?" to get the status and it is always 0 even if it not able to deliver the file.

Can anyone please help me out in this. This is very urgent.

Here is the script:
sftp $1@$2 <<EOC

cd $3

lcd $4

put $5

EOC

if [ $? -ne 0 ]
then
echo "SFTP ERROR" >> FILE
exit 9
fi

echo "SFTP Complete" >> FILE

Here is the java code:

//Execute the shell script which drops the file to destination using SFTP
Process process = runtime.exec("sftpFile.sh" +" " +user+" " + host+" " + targetfile+" " + localDir +" "+fileName,null,dir);

process.waitFor();

Any help is appreciated.

Thanks in Advance
  #2 (permalink)  
Old 10-11-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
ftp and sftp are supposed to write status codes(ftp) or messages(sftp) to stdout, the $? value of sftp, if it connects okay to a remote host, will be 0. The status of an individual operation is displayed on stdout. "OK" means whatever operation was attempted completed succesfully.

However, the actual text you get back may depend on whose sftp you use. So checking for errors is interesting.
Consider libcurl classes for your java? There are libcurl routines that will perform sftp operations and give you a status back.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0