How to confirm SFTP file delivery? How to confirm SFTP file delivery? unix unix

How to confirm SFTP file delivery?


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@hostif [ $? -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.


I know this is an old thread...Here's the best I've been able to come up with for password auth uploading into a blind folder using the openssh sftp client.(It was a lot more exact with ftp...)

SSHPASS=${PASSWORD} sshpass -e sftp -vvv -oStrictHostKeyChecking=no -oBatchMode=no -b - ${LOGON}@${FTPSITE} >${LOB}ftp.log 2>&1 <<EOFpwdcd uploadput ${XMTFILE}quitEOF# sftp does not use FTP codes - it only gives the final status of the requested operationStatus=$?# Not perfect, but sending a single file using -vvv should produce 2 lines containing "debug3: SSH2_FXP_STATUS 0"Tmp=`grep "debug3: SSH2_FXP_STATUS 0" ${LOB}ftp.log | wc -l`[ ${Tmp} -ne 2 ] && Status=1 # Override sftp exit value based on log info


For a completely arbitrary server implementation, this is not possible. It's often desirable to make incoming directories write-only to untrusted users, to prevent abuse of publicly (or otherwise widely) accessible file servers (such as using them to host unrelated content; once upon a time, FTP servers with stolen credentials were often used by pirates -- preventing uploaded content from being downloaded without administrative review prevents this). Thus: If the server administrator chooses not to let you see uploaded files, then, well, you can't see uploaded files.

However -- the SFTP protocol provides a contract: If you tell the server to close a handle after writing to it, and the server says that all involved operations succeeded without error, then if the file wasn't successfully received (whatever the server then decides to do with it, which may or may not include making it accessible for downloads), this is indicative of a server-side bug and is not the fault of your SFTP client.

When I was last implementing a custom SFTP server -- for customer support purposes, implemented using Paramiko -- I sent email notifications after successful uploads; obviously, though, that's an implementation-specific behavior).