user1726550
user1726550

Reputation: 81

unix sftp issue

I am not posting entire code here but part of it.Below code giving errors.I am trying to store all sftp commands and then performing actual sftp.

export SFTP_BATCH_FILE='/var/tmp/SFTP_BATCH_FILE'

#------------------------------------------------------------------------
# Create sftp script
#------------------------------------------------------------------------
rm -f $SFTP_BATCH_FILE
echo "lcd $SOURCE_FILE_DIRECTORY " > $SFTP_BATCH_FILE
echo "cd $DESTINATION_FILE_DIRECTORY " >> $SFTP_BATCH_FILE
if [ -z $FILE_TO_UPLOAD_TESTD ] then
echo "put $FILE_TO_UPLOAD_TESTD " >> $SFTP_BATCH_FILE
fi
if [ -z $FILE_TO_UPLOAD_TESTDF ] then
echo "put $FILE_TO_UPLOAD_TESTDF " >> $SFTP_BATCH_FILE
fi
echo "bye" >> $SFTP_BATCH_FILE

#------------------------------------------------------------------------
# Do sftp
#------------------------------------------------------------------------
echo " Before SFTP " >> $LOG_FILE
if [[ -z $ FILE_TO_UPLOAD && -z $ FILE_TO_UPLOAD1 ]] then
 echo “No files to transfer” >> $LOG_FILE
       mv $LOG_FILE $LOG_DIRECTORY
 exit 1
else 
echo “Attempting to connect to  Remote Server $REMOTE_SERVER_PROD” >> $LOG_FILE
/usr/bin/sftp –v -oPort=$SFTP_PORT -b $SFTP_BATCH_FILE $SOURCE_FUNCTIONAL_ID@$REMOTE_SERVER_PROD >> $LOG_FILE 2 >> $LOG_FILE
fi

Errors i am getting:

rm: /var/tmp/SFTP_BATCH_FILE is a directory

test.ksh[89]: /var/tmp/SFTP_BATCH_FILE: cannot create

test.ksh[90]: /var/tmp/SFTP_BATCH_FILE: cannot create

Regards,

Chai

Upvotes: 0

Views: 126

Answers (1)

beny23
beny23

Reputation: 35048

The clue is in the error message

rm: /var/tmp/SFTP_BATCH_FILE is a directory

As the directory is still there your subsequent commands cannot create the SFTP_BATCH_FILE file.

rm -f cannot remove directories. Use rm -rf instead.

Edit:

Just to clarify, -r is recursive meaning that directories are delete as well, -f is force which means that nonexistent files/directories don't cause an error and the command doesn't prompt.

Upvotes: 1

Related Questions