SFTP error: no such file or directory


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers SFTP error: no such file or directory
# 1  
Old 11-07-2008
SFTP error: no such file or directory

Hi All,

I am using a shell script for SFTPing the files to target server. The problem which I am facing is that even if the files are not transferred, the script finishes successfully. I want the script to fail in case the remote directory does not exists.

The script which I am using is as follows:

NO_OF_RETRY_ATTEMPTS=5
RETRY_INTERVAL=1
RETRY_COUNTER=1
while [ $RETRY_COUNTER -lt $NO_OF_RETRY_ATTEMPTS ]
do
echo $RUN_ID : Trying To Connect To The SFTP Location : $HOST Attempt No : $RETRY_COUNTER >> $SFTP_LOG


sftp -o "IdentityFile $HOME/.ssh/id_rsa" $USER@$HOST <<EOF 1> ${SFTP_LOG} 2> ${SFTP_LOG}
cd $REMOTE_PROCESSING_ZONE
lcd $PROCESSING_ZONE
mput $FILENAME
chmod 777 $FILENAME

bye

EOF

if [ -f $SFTP_LOG ]
then
RESPONSE_MSG=`grep -c "No such file or directory" $SFTP_LOG`
if [ $RESPONSE_MSG -gt 0 ]
then
echo $RUN_ID : The Remote Directory Does Not Exist. >> $SFTP_LOG
RETURNCODE=1
exit $RETURNCODE
fi

RESPONSE_MSG=`grep -c "Connection timed out" $SFTP_LOG`
if [ $RESPONSE_MSG -gt 0 ]
then
echo $RUN_ID : Could Not Connect To FTP Location In Attempt - $RETRY_COUNTER >> $SFTP_LOG
RETRY_COUNTER=$RETRY_COUNTER + 1

if [ $RETRY_COUNTER -lt $NO_OF_RETRY_ATTEMPTS ]
then
echo $RUN_ID : Waiting For $RETRY_INTERVAL Before Re-Attempt.>> $SFTP_LOG
sleep $RETRY_INTERVAL
else

echo $RUN_ID : Could Not Connect To FTP Location Event After Re-Attempts.>> $SFTP_LOG
RETURNCODE=2
exit $RETURNCODE

fi

else
echo $RUN_ID : The File Has Been Transferred To The Target Zone. >> $SFTP_LOG
RETURNCODE=0
exit $RETURNCODE
fi

fi
done


In this script, I am trying to search for the error message in log file but the problem is there is no error message in log file even if $REMOTE_PROCESSING_ZONE does not exists.
My concern is that for handling the errors , atleast the errors should be present in log file.

Can anybody guide how to correct this issue. The same script was working fine 2 days back but not now.

Thanks in advance
# 2  
Old 11-07-2008
sorry, me and others of cource gently wana help you. but nobody wants to analyze a 50 liner. bring your problem to the point and you will get a replay soon
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Error while renaming the file in SFTP Session

Hi All Below is the script I am trying to execute to rename a file in an SFTP session. It is in GNU/Linux. This script is for generic use and so I am passing arguments. Everything in the script works fine except "reading the filename in SFTP session" In the below script the... (2 Replies)
Discussion started by: sparks
2 Replies

2. UNIX for Advanced & Expert Users

Sftp user chrooted in a directory

Hello, I have a task to create 3 users that must connect only via sftp on a machine, and must have only read access to a certain directory (thay shouldn;t be able to cd anywhere else) The problem is that the directory where these users must have access to, it's already created/owned by another... (0 Replies)
Discussion started by: black_fender
0 Replies

3. UNIX for Dummies Questions & Answers

File Listing from remote to loca directory using SFTP

Hello, Using ftp i was able to get a directory listing to local directory. ftp - i <host_name> ftp <user> ftp <password> dir <dir> 200 PORT command successful 150 Opening ASCII mode data connection for file list -rw-rw-r-- 1 <uuu> <kkk> 160384 Apr 13 19:38 walmart.txt 226... (5 Replies)
Discussion started by: pavan_test
5 Replies

4. Shell Programming and Scripting

[Solved] SFTP error - Couldn't close file: Failure

I am trying to send a file from my 9000 box to a vendor using sftp and I am getting this error: Couldn't close file: Failure Here are the results of my automated script: Connected to yyy.com. sftp> pwd Remote working directory: / sftp> cd xxxxx/yyyyy_TEST/TEST sftp> put FILE FILETEST... (1 Reply)
Discussion started by: nickg
1 Replies

5. Shell Programming and Scripting

SFTP-how to log individual sftp command error while executing shell script

Hi, I have situation where i need to automate transferring 10000+ files using sftp. while read line do if ; then echo "-mput /home/student/Desktop/folder/$line/* /cygdrive/e/folder/$line/">>sftpCommand.txt fi done< files.txt sftp -b sftpCommand.txt stu@192.168.2.1 The above... (1 Reply)
Discussion started by: noobrobot
1 Replies

6. Shell Programming and Scripting

SFTP Does directory exist?

Hi, Im trying to add some validation into my shell script code that basically checks whether a directory exists before SFTP'ing a file to it. If the directory exists then it will add the file, if not then it should return some kind of message. This is the code I have written so far but with no... (1 Reply)
Discussion started by: Jack_Maloney
1 Replies

7. Solaris

Restricting SFTP user to a defined directory and home directory

Hi, I've created solaris user which has both FTP and SFTP Access. Using the "ftpaccess" configuration file options "guest-root" and "restricted-uid", i can restrict the user to a specific directory. But I'm unable to restrict the user when the user is logged in using SFTP. The aim is to... (1 Reply)
Discussion started by: sftpuser
1 Replies

8. Shell Programming and Scripting

sftp can't fine batchfile "No such file or directory"

Hi, I've got a C program that is using execlp to run a non-interactive sftp (using a batchfile) session to send some files to another system. Just before doing that, I create the batchfile called sftp_batch on the fly: V8_26_1:sun-->cat /workspace/sftp_batch cd /tmp/newsftp put test.file... (2 Replies)
Discussion started by: Fiaran
2 Replies

9. Shell Programming and Scripting

Error transferring large file using sftp protocol

Hello All, I am not able to transfer large file completely (more than 60 MB) through automated SFTP script. It transfers only the partial file (approximately 55 MB) and it stops. I use "expect" command to transfer file in a automatic mode through script. The file transfer rate i get is around... (0 Replies)
Discussion started by: prashant.patel
0 Replies

10. Shell Programming and Scripting

creating a file on remote directory using sftp

Hi, My requirement is to sftp a file from one server to another.After the file is completely transferrred, i should be able to create a text(dummy) file on the remote directory. How could this be accomplished. Any suggestions? (1 Reply)
Discussion started by: borncrazy
1 Replies
Login or Register to Ask a Question