linux - 如何确认 SFTP 文件传送?

标签 linux unix ssh sftp

我正在使用 SFTP 和非 root 用户的公钥发送文件,看起来文件已发送,但我无法在目标文件夹中找到它,可能是由于权限问题。

sftp> ls
sftp> put /tmp/testx
Uploading /tmp/testx to /folder1/target_folder
/tmp/testx                                 100%    5     0.0KB/s   00:01
sftp> get testx
Couldn't stat remote file: No such file or directory
File "/folder1/target_folder/testx" not found.
sftp> ls
sftp>

这是 -vvv :

debug3: SSH_FXP_REALPATH . -> /folder1
debug3: Looking up /tmp/file_to_send
debug3: Sent message sender_host 4 T:17 I:2
debug3: Wrote 80 bytes for a total of 2653
debug3: Received stat reply T:105 I:2
debug3: Sent message SSH2_FXP_OPEN I:3 P:/folder1/target_directory/file_to_send
debug3: Wrote 112 bytes for a total of 2765
debug3: Sent message SSH2_FXP_WRITE I:4 O:0 S:6206
debug3: Wrote 6288 bytes for a total of 9053
debug3: SSH2_FXP_STATUS 0

目标目录

 drw-rw-rw-    1  0   0       target_directory

如何在没有服务器访问权限的情况下确保文件已交付?

最佳答案

您所能做的就是在上传文件时检查没有错误。这就是 SFTP 服务器为您提供的所有信息。

使用命令行 OpenSSH sftp 客户端,您可以检查其退出代码(您需要使用 -b 开关)。

echo "put file.txt" | sftp -b - user@host
if [ $? -eq 0 ]
then
    echo "File uploaded"
else
    echo "File NOT uploaded"
fi

另见 How to perform checksums during a SFTP file transfer for data integrity?


SFTP 服务器很可能不允许您下载刚刚上传的文件。

这种行为有两个常见原因:

  • 公共(public)“上传”目录。这是为了防止您下载其他用户的文件。
  • 有一些进程会立即选择上传的文件进行某些处理。

关于linux - 如何确认 SFTP 文件传送?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28223890/

相关文章:

linux - 即使文件系统已满,那么linux系统也能正常工作。这是怎么发生的?

c - 构建 Linux 调试器 C

file - 你如何删除unix sh中以 "string"开头的所有行?

linux - 使用 bash 命令删除下一行、空格

ubuntu - Vagrant Master 和 Slave Boxes - SSH key 设置

Git SSH 协议(protocol)记住密码

python - linux 模块未找到错误 : No module named '_ctypes

c# - 位于 linux 服务器上的 PHP 代码需要运行 windows .exe

unix - 为什么在 TCP 连接关闭后文件描述符仍然存在?

ssh - 如何通过 JSch : port forwarding, ssh 命令或 SSH 隧道多次 ssh?