2
import paramiko
import os

paramiko.util.log_to_file('logfile.log')

host = "100.10.89.23"
port = 22
transport = paramiko.Transport((host, port))
password = "pass"
username = "user"
transport.connect(username = username, password = password)

sftp = paramiko.SFTPClient.from_transport(transport)

filepath = '/import/TMP'
localpath = 'F:\\Projects\\Test'
sftp.get(filepath, localpath)

sftp.close()
transport.close()

ftp_priv_key is not required to connect to sftp. Suppose I have 10 files in the given sftp path, out of which 6 files are in csv format and other or in different format. My requirement is to copy only the csv format files.

1 Answer 1

2

You will need to do something like:

sftp = paramiko.SFTPClient.from_transport(transport)
for filename in sftp.listdir(filepath):
    if filename.endswith('.csv'):
        sftp.get(filename, localpath)
Sign up to request clarification or add additional context in comments.

4 Comments

Making changes the way you suggest & while running the code i got the following error: 1. Python36\lib\site-packages\paramiko\sftp_client.py" line 721 size = self.getfo(remotepath, fl, callback) 2.Python36\lib\site-packages\paramiko\sftp_client.py" line 695 file_size = self.stat(remotepath).st_size 3.Python36\lib\site-packages\paramiko\sftp_client.py" line 413 t, msg = self._request(CMD_STAT, path) 4.Python36\lib\site-packages\paramiko\sftp_client.py" line 730 return self._read_response(num) 5. Python36\lib\site-packages\paramiko\sftp_client.py" line 781 self._convert_status(msg)
6. Python36\lib\site-packages\paramiko\sftp_client.py" line 807 raise IOError(errno.ENOENT, text)
Stephen Rauch,, Its really appreciating if you suggest what's missing?
This does not help. Which line failed?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.