【问题标题】:Python PySFTP transfer files from one remote server to another remote serverPython PySFTP 将文件从一台远程服务器传输到另一台远程服务器
【发布时间】:2016-05-03 03:12:11
【问题描述】:

我一直在使用 pysftp 成功地将文件从远程服务器传输到本地服务器。这是我的代码的简单版本:

class SftpClass(object):
    def __init__(self):
        self.sftp = None  


    def connect_to_sftp(self, sftp_host, sftp_username):

        # initiate SFTP connection
        self.sftp = pysftp.Connection(sftp_host, sftp_username)

    def sftp_get_file(self, local_directory, remote_directory, file):

        # pull file from remote directory and send to local directory
        self.sftp.get(file in remote_directory, file in local_directory)

这是因为我的本地和远程目录都在同一个 linux 服务器上。但是如果他们的远程目录在不同的服务器上呢?如何确保脚本仍能运行并成功地将文件从单独的远程服务器传输到我的个人远程服务器?

【问题讨论】:

    标签: python pysftp


    【解决方案1】:

    如果我正确理解您的问题,您应该先从一台服务器复制到一个临时本地文件,然后再将其复制到另一台服务器。

    【讨论】:

    • 有道理,谢谢。我希望有一种方法可以使用两组主机和用户名,以便允许两个远程服务器在一个步骤中来回传输数据,但我想我可以使用我的本地目录作为中间人
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-03
    • 1970-01-01
    • 2020-08-31
    • 1970-01-01
    • 2017-03-29
    • 1970-01-01
    • 2022-11-05
    相关资源
    最近更新 更多