1

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?

13
  • What returns None? Commented Jun 1, 2017 at 14:18
  • @martineau content of file is empty and it returns None, but it doesn't empty. I need to read that and add to dataframe Commented Jun 1, 2017 at 14:19
  • What is the value of all_files? Commented Jun 1, 2017 at 14:20
  • @errata It's list. I filter list in directory and next I add it's name to sftp.get() Commented Jun 1, 2017 at 14:21
  • @PetrPetrov I know it is a list, I was asking for a value of it? :) Commented Jun 1, 2017 at 14:24

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

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.