Home » Questions » Computers [ Ask a new question ]

Is there a way to tell if a file is done copying?

Is there a way to tell if a file is done copying?

The scenario is this: Machine A has files I want to copy to Machine C. Machine A can't access C directly, but can access Machine B that can access Machine C. I am using scp to copy from Machine A to B, and then from B to C.

Asked by: Guest | Views: 24
Total answers/comments: 3
Guest [Entry]

"A common way of doing this is to first copy it to a temporary file name, preferably a hidden file. When the copy finishes, the script that is doing the copy then renames it to the non-hidden filename.

The script on machine B could then watch for non-hidden files.

The script on machine A would look something like this:

for file in `ls *` ; do
scp $file user@host:~/.${file}.tmp
ssh user@host ""mv ~/.${file}.tmp $file""
done

Although this does not satisfy OP's desire to use the one-line

scp * user@host:~/

it accomplishes the same thing and also allows machine B to transfer each file as it finishes without waiting for the next file."
Guest [Entry]

"I just thought of another, completely unrelated option. Doesn't use scp at all. Please let me know if this would work:

on B, create a fifo pipe somewhere:
mkfifo /tmp/xfer
on A, don't use scp, instead, tar
-cz files | ssh B 'cat > /tmp/xfer
on C, run ssh B 'cat /tmp/xfer' |
tar -xz

This way, data isn't stored on B, it just passes through the pipe. The downside to this is, you can only have one copy going at a time...

You'll need to make sure the process on C respawns each time it finishes."
Guest [Entry]

"The copy will either run as a another process, or you could force it to, using a subshell. Then, you could use ps to ""watch"" the process and see when it disappears.

Also, I believe that in *nix, you can delete the file while it's being copied. The system won't delete it until the copy program closes it. Of course, if the copy doesn't succeed, you lose the file, so, not the best idea."