I am using scp to transfer files between two linux systems - when the transfer finishes, the final print to screen from SCP shows the wrong file size:
vmtbackup.zip 100% 2613MB 17.5MB/s 02:29 .
As you can see here, the final reported size is 2613MB and the transfer has completed. However the actual size of the file is 2741MB
When I check on the target system, the file has the correct size (so the transfer has completed successfully).
I am using the output from SCP as part of a script, and the check condition to finish the script is when the size in SCP = the size of the file (as the 100% is equally unreliable) - it's part of an expect script, which looks like this:
function Transfer {
/usr/bin/expect <<EOD
#transfers the vmtbackup.zip file from source system to target system
spawn scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/vmtbackup.zip $user@$ip:/tmp/
expect {
#handles all unexpected outcomes. Primarily used to capture wrong
password, as no remote connection should be caught earlier in migration.sh
default {
send_user "\nERROR: I was unable to connect to $ip for some reason. Please try again.\n"
exit 1
}
#passes the password defined in migration.sh to scp password prompt"
-re "root@$ip's \[pP\]assword:" {
send -- "$password\r"
exp_continue
}
-re "\[pP\]assword:" {
send -- "$password\r"
exp_continue
}
-re "ETA" {
exp_continue
}
#when file transfer reaches 100%, exits script
-re "$si" {
exit 0
}
EOD
}
I'm aware of the security implications of using password in plaintext and that I should use SSL, but for now that's not part of the problem.
Can anyone tell me why SCP behaves in this way?