0

I've been using pysftp to successfully transfer files from a remote server to a local server. Here's what the simple version of my code looks like:

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)

This works because my local and remote directories are both on the same linux server. But what if they remote directory was on a different server? How can I make sure the script would still run and successfully transfer files from the separate remote server to my personal remote server?

taleinat
  • 8,441
  • 1
  • 30
  • 44
ProgrammingWithRandy
  • 725
  • 3
  • 14
  • 31

1 Answers1

1

If I understand your question correctly, you should first copy from one server to a temporary local file, and then copy that over to the other server.

taleinat
  • 8,441
  • 1
  • 30
  • 44
  • That makes sense, thank you. I was hoping there was a way to use two sets of hosts and usernames in order to allow two remote servers to transfer data back and forth in a single step, but I guess I can use my local directory as a middle-man – ProgrammingWithRandy Jan 26 '16 at 17:16