Scp cannot guarantee that a copy will happen correctly. No software can guarantee that a copy will take place correctly. There is always the possibility that the power or the network will go down, or a source file turns out to be unreadable, or the destination volume fills up, etc.
The most a file copy software can do is to guarantee that when it exits, either the copy was correct, or the software reports an error. The reliable way to check for errors is to check the return status of the process: 0 for success, any other value for error. Scp, like any halfway decent program, does return 0 on success and a nonzero value on failure.
Your expect script does not check the return status of scp
, therefore you have no way to know whether scp told you that the copy was successful.
Expect is not a useful tool here. You should really use public key authentication. If you really, really can't set up keys, then use sshpass rather than rolling your own.
Also, you should use rsync rather than scp. Rsync has a major advantage: if a copy is interrupted, you can run it again and it'll take where it left off. Be sure to tell it to preserve timestamps, and also other metadata unless you have a good reason not to:
rsync -a SOURCE/ DESTINATION/
expect
to runscp
and lost some files. You did not say what commands were executed or where the files were lost (on server or client). You also do not mention any error messages or warnings. Please [edit] your question to provide more details. – Kusalananda Oct 25 '17 at 11:45