sqlpractice
sqlpractice

Reputation: 141

SFTP Transfer completion status

I have a SFTP code to get file from the remote server to my local server using "expect".Below is the snippet from my shell script.

/usr/bin/expect<<EOF
spawn /usr/bin/sftp -o Port=$PORT $USER@$HOST
expect "$USER password:"
send "$PASSWORD\r"
expect "sftp>"
set timeout -1
send "get $FILE $LOCAL\r"
expect "sftp>"
send "bye\r"
sleep 1
EOF

My requirements: Is there a way to check the completion of the transfer?

I am open to any suggestions - Checking on the basis of file size(this will be a great solution but I suppose limitation of sftp commands will not allow to compare the sizes of the source and transferred file).

Or is there a way to check on the basis of return codes?i.e. if get is 100% it returns 0 otherwise any non zero code.If this is a way how to test it ? I mean how to capture the partial transfer?or network issue ?or any other expected scenarios?

I am open to any solution other than expect as well.Like working in sftp batch mode or other sftp options,if any?

I am using AIX unix and I am bound to use SFTP only.

Thanks in Advance!

Upvotes: 0

Views: 1632

Answers (1)

Ivan G
Ivan G

Reputation: 11

I would use SCP instead of SFTP. Shell return codes as completion status. As for downloaded artifact integrity, best way is to put md5 checksum near file which you are downloading and verify against it after download completes. So you have file.tar and file.md5 (which made by md5sum file.tar > file.md5) you downloading both and make verification.

If you have some other script which should wait until download completes, to process downloaded files it is better to create .lock file when download starts and delete it after. Processing script should wait until .lock file disappears.

Upvotes: 1

Related Questions