Secure Copy File from remote server via scp and os module in Python

蓝咒 提交于 2019-12-01 05:49:54

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])])
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!