简体   繁体   中英

linux sftp :file transfer error

I have a small problem regarding "sftp".

I have a script, which simply transfers a file to a remote sftp server. But when this script runs it fails at sftp and my script fails. So, i have to manually transfer the file,using command which is same as the command that i have used in the script, and it works fine.

So my problem is that the sftp command runs smoothly when i run it manually, but creates problem when the same command is run through the script.

this is the code that I'm using

sftp -v -b sftp_input.txt UserId@aa.bb.cc.dd 
if (($? > 0 ));
then
   echo "sftp  error. Exiting.."
   exit
fi

where sftp_input.txt contains the cmd to put the file to remote server.

Please advice.....

The script can't work because it's malformed. You forgot to separate the if statement and also forgot the closing fi . Here's the correct form for your script:

sftp -v -b sftp_input.txt UserId@aa.bb.cc.ddd
if (($? > 0 )); then
    echo "sftp error. Exiting.."
    exit
fi

If you want it all in one line, then:

sftp -v -b sftp_input.txt UserId@aa.bb.cc.ddd; if (($? > 0 )); then echo "sftp error. Exiting.."; exit; fi

But as you can see it's a bad idea. Better to write readable and well indented code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM