[英]linux sftp :file transfer error
I have a small problem regarding "sftp". 关于“ sftp”,我有一个小问题。
I have a script, which simply transfers a file to a remote sftp server. 我有一个脚本,该脚本只是将文件传输到远程sftp服务器。 But when this script runs it fails at sftp and my script fails. 但是,当该脚本运行时,它在sftp上失败,并且我的脚本失败了。 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. 所以我的问题是,当我手动运行sftp命令时,它运行平稳,但是在脚本中运行相同的命令时却出现问题。
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. 其中sftp_input.txt包含将文件放置到远程服务器的cmd。
Please advice..... 请指教.....
The script can't work because it's malformed. 该脚本格式错误,因此无法正常工作。 You forgot to separate the if
statement and also forgot the closing fi
. 您忘记了分隔if
语句,也忘记了结束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. 更好地编写可读性强的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.