scp.py
scp.py copied to clipboard
Recursive transfers fail on directory already existing
This issue is very similar to #32. I actually found another similar scenario that throws an SCPException and breaks the process. This one is when you are copying a file to a destination that has a directory that is the same name as the file that you are copying. Here is an example where I try to recursively copy one directory to a remote device. In the local directory, there is a file gres-tp, and in the remote directory there already existed a directory gres-tp/, creating the following stack trace:
Traceback (most recent call last):23123123
File "jaide.py", line 345, in copy_file
scp.put(scp_source, scp_dest, recursive=True, preserve_times=True)
File "build/bdist.macosx-10.9-intel/egg/scp.py", line 101, in put
File "build/bdist.macosx-10.9-intel/egg/scp.py", line 217, in _send_recursive
File "build/bdist.macosx-10.9-intel/egg/scp.py", line 170, in _send_files
File "build/bdist.macosx-10.9-intel/egg/scp.py", line 251, in _recv_confirm
scp.SCPException: scp: /var/tmp///gres-tp: Is a directory
The recursion stops and any other files/folders are not copied. For completeness, here is an example of the scp command handling this:
$ scp -r ~/desktop-link/scp/tmp/* [email protected]:/var/tmp
[email protected]'s password:
asdf 100% 0 0.0KB/s 00:00
asdf123 100% 0 0.0KB/s 00:00
asdf123123123 100% 0 0.0KB/s 00:00
scp: /var/tmp/gres-tp: Is a directory
hello-world 100% 0 0.0KB/s 00:00
marking-scheme 100% 0 0.0KB/s 00:00
template 100% 281 0.3KB/s 00:00
A solution here would be for the user to provide a callback, which would receive the error and decide whether to go on or abort. We can't go on copying after a file failed to transfer...
This is what shutil does (onerror parameter to rmtree()).