1
sftp.get(remotepath, localpath) #for sftp to localdrive
upload = client.folder(Folder_id).upload(localpath) #localdrive to box

Using Python I'm downloading files from SFTP server to local drive and then from local drive to my box.

Is that possible to upload my files to box directly from SFTP server using Python without saving the file to local drive?

I'm using Paramiko and Box SDK.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
kar_n
  • 78
  • 7

1 Answers1

2

You can use SFTPClient.open to open a file on an SFTP server as if it were a local file. It returns a file-like object. You can then use the object with Folder.upload_stream:

with sftp.open(remotepath, "rb") as flo:
    flo.prefetch()
    client.folder(folder_id).upload_stream(flo, file_name)

For the SFTPFile.prefetch call, refer to:
Reading file opened with Python Paramiko SFTPClient.open method is slow

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992