Reputation: 4432
I need to get files from server and next write them to database. I use:
with pysftp.Connection(host, username=username, password=password, cnopts=cnopts) as sftp:
sftp.chdir('path')
all_files = [file_name for file_name in sftp.listdir() if 'access' in file_name]
today_log = all_files[0]
all_files = all_files[1:]
df = df.append(sftp.get(str(today_log)))
But it returns None
.
How can I get content from file and write it to dataframe?
Upvotes: 1
Views: 1102
Reputation: 202088
If I understand your question correctly, you want to read the file from SFTP server into a variable/memory.
For that, you need to use .getfo
, like:
flo = BytesIO()
sftp.getfo(remotepath, flo)
Alternatively, use Paramiko library directly (without the pysftp wrapper).
See Read a file from server with ssh using python.
Upvotes: 1