簡體   English   中英

Python PySFTP將文件從一台遠程服務器傳輸到另一台遠程服務器

[英]Python PySFTP transfer files from one remote server to another remote server

我一直在使用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服務器上。 但是,如果他們的遠程目錄位於其他服務器上怎么辦? 如何確保腳本仍將運行並成功將文件從單獨的遠程服務器傳輸到我的個人遠程服務器?

如果我正確理解了您的問題,則應首先從一台服務器復制到一個臨時本地文件,然后再將其復制到另一台服務器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM