How to copy a file to a remote server in Python using SCP or SSH? -
i have text file on local machine generated daily python script run in cron.
i add bit of code have file sent securely server on ssh.
if want simple approach, should work.
you'll want ".close()" file first know it's flushed disk python.
import os os.system("scp file user@server:path") #e.g. os.system("scp foo.bar joe@srvr.net:/path/to/foo.bar")
you need generate (on source machine) , install (on destination machine) ssh key beforehand scp automatically gets authenticated public ssh key (in other words, script doesn't ask password).
Comments
Post a Comment