Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
636 views
in Technique[技术] by (71.8m points)

linux - How to confirm SFTP file delivery?

I am sending a file using SFTP and public key for non-root user, looks like the file is sent, but I cant find it on the target folder, maybe due to permission.

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>

here is the -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

target directory

 drw-rw-rw-    1  0   0       target_directory

How can I make sure the file is delivered, without server access ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

All you can do is to check that there are no errors, when uploading the file. That's all information the SFTP server gives you.

With command-line OpenSSH sftp client, you can check its exit code (you need to use the -b switch).

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

See also How to perform checksums during a SFTP file transfer for data integrity?


It's perfectly possible that the SFTP server does not allow you to download a file that you have just uploaded.

There are two common reasons for such behavior:

  • Public "upload" directory. This is to prevent you from downloading other user's files.
  • There's some process that immediately picks uploaded file for some processing.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...