【问题标题】:Send matching/wildcard file to another server using sftp.put in Python在 Python 中使用 sftp.put 将匹配/通配符文件发送到另一台服务器
【发布时间】:2020-06-18 22:53:05
【问题描述】:

所以我试图将某个文件从我的本地服务器发送到另一台服务器。如果我知道具有确切名称的文件,我可以发送文件。 Bur 我真正想要做的是选择一个具有匹配名称的文件并发送相同的文件。

例如我的文件名是filename_:test_file_20190918 我想提取所有匹配 test_file_* 的文件

这是我想要做的,但它似乎没有工作

import paramiko
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname='host_name',username='username',password='pwd',port=22)
sftp_client=ssh.open_sftp()

sftp_client.put("/home/mylocation/test_file_*",'/incoming/test_file_send*')

sftp_client.close()
ssh.close()

【问题讨论】:

    标签: python ssh sftp paramiko pysftp


    【解决方案1】:

    Paramiko 不支持通配符。

    在调用SFTPClient.put之前,您必须自己找到正确的文件。

    Get a filtered list of files in a directory


    强制警告:请勿使用AutoAddPolicy,除非您不关心安全性。这样您就失去了对 MITM 攻击的保护。
    有关正确的解决方案,请参阅Paramiko "Unknown Server"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-24
      • 1970-01-01
      • 1970-01-01
      • 2018-08-29
      • 2012-09-23
      • 1970-01-01
      • 2015-06-25
      • 2013-12-24
      相关资源
      最近更新 更多