linux - 获取SFTP错误的命令

标签 linux shell unix sftp

谁能告诉我如何解决使用 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/

相关文章:

shell - Applescript Shell 脚本进度

bash脚本创建多个文件并在每个文件中增量替换字符串

c - times() 系统调用的开销 - 相对于文件操作

c++ - 使用 make 编译简单的 C++ 项目

linux - Linux 内核中的 parse_elf() 中的段是在哪里复制的?

linux - 如何在 bash 中使用 awk 编写条件来转置文件?

我可以通过堆栈转储判断一个进程是被杀死还是它自己崩溃了吗?

c - 时间延迟 (Linux)/(Windows)

linux - 在正文中使用 & 参数测量 bash 脚本的运行时间

bash shell 脚本 : How to group argument list into N items?