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!





Maybe you should authenticate via ssh-keys and forget expect.
– Lorinczy Zsigmond
Aug 30 at 11:30





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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế