I\'m pretty new to Python and programming. I\'m trying to copy a file between two computers via a python script. However the code
os.system(\"ssh \" + hostna
I think the easiest (to avoid having to enter a password) and most secure way to go about this is to first set public/private key authentication. Once that is done, and you can log in to the remote system by doing ssh user@hostname
, the following bash command would do the trick:
scp some/complete/path/to/file user@remote_system:some/remote/path
The corresponding Python code would be:
import subprocess
filepath = "some/complete/path/to/file"
hostname = "user@remote_system"
remote_path = "some/remote/path"
subprocess.call(['scp', filepath, ':'.join([hostname,remote_path])])