如何使用 pscp 将 python 脚本中创建的文件复制到需要密码的远程服务器



我需要将许多在python脚本中创建的文件从本地复制到远程服务器。在命令提示符下,我使用此行:

"pscp c:\users\myaccount\documents\foler\file.txt name@server:/home/folder"。

但这需要一个密码,我可以在命令提示符下输入该密码。

在我的 python 脚本上,我"导入操作系统"然后:

cmd = "pscp local_path server_path"

os.system(cmd)

但是我不知道如何在脚本中输入密码。

谢谢

尝试使用paramiko包 https://docs.paramiko.org/en/2.4/

s = paramiko.SSHClient()
    s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    s.connect("xxx.xxx.xxx.xxx",22,username=xxx,password='',timeout=4)
    sftp = s.open_sftp()
    sftp.put('/home/me/file.ext', '/remote/home/file.ext')

最新更新