Search code examples
pythonpysftp

Get subfolders from pysftp Connection


I have an admin account where customers upload files in a subdirectory.

import pysftp as sftp
import os

cnopts = sftp.CnOpts()
cnopts.hostkeys = None  

s = sftp.Connection(host=myHostname, username=myUsername, password=myPassword, cnopts=cnopts)
folderlist = s.listdir()

This gives me back the following array:

['Customer_1', 'Customer_2', 'Customer_3', 'Customer_4']

folderlist[0].listdir() does not work here. How can I access the subdirectories?


Solution

  • Try this

    s.listdir(remotepath=folderlist[0])
    

    folderlist[0] is a string.