谁能告诉我如何解决使用 SFTP 传输文件时发生的错误。 在文件传输过程中是否有任何命令可以获取 SFTP 中的错误?我正在使用 SFTP 传输大约 10 个文件。假设我在传输第 9 个文件时出错,如何在 SFTP 中获取错误和导致错误的文件名?
最佳答案
您可以将 sftp STDOUT/STDERR 重定向到日志文件(使用 > logfile 2>&1 ),在其中可以解析以查找错误(如果有)。好的部分是 sftp 只有在 session 期间出现任何错误时才返回非零,否则它返回零。
# for batch mode
# will return zero if there was no error while executing commands in sftpcommand.txt file
sftp -b sftpcommand.txt user@server > /tmp/sftp.log 2>&1
sftp_return=$?
if [ $sftp_reutrn -ne 0 ];
then
echo "Some error during sftp ... check /tmp/sftp.log file"
else
echo "No error during sftp"
fi
关于linux - 获取SFTP错误的命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25051070/