SFTP Transfer completion status
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 "$PASSWORDr"
expect "sftp>"
set timeout -1
send "get $FILE $LOCALr"
expect "sftp>"
send "byer"
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!
Can u please provide more details .. thanks!
– sqlpractice
Aug 31 at 9:30
Quickstart:
ssh-keygen -A; ssh-copy-id remoteuser@remotehost
after this you can use sftp remoteuser@remotehost
without password.– Lorinczy Zsigmond
Aug 31 at 9:52
ssh-keygen -A; ssh-copy-id remoteuser@remotehost
sftp remoteuser@remotehost
Ok thanks ! Can u explain more as how will it fulfill my requirements..file size comparison and/or file download completion status
– sqlpractice
Aug 31 at 9:59
You would be able to perform sftp from shell script (batch mode), without using expect, eg:
printf $'cd somedirnget somefilenquit' | sftp remoteuser@remotehost
– Lorinczy Zsigmond
Aug 31 at 12:18
printf $'cd somedirnget somefilenquit' | sftp remoteuser@remotehost
1 Answer
1
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.
file.tar
file.md5
md5sum file.tar > file.md5
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.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Maybe you should authenticate via ssh-keys and forget expect.
– Lorinczy Zsigmond
Aug 30 at 11:30