1

I am trying to access csv files in an ftp server called Folder 1. After accessing the folder1 I am trying to loop through all csv's and place them in a dataframe. My goal is to append all the csv's together into one dataframe. Currently this is what I see when running the following code:

import ftplib
with ftplib.FTP('ftpserver.com') as ftp:
    ftp.login('username','Pw')
    ftp.cwd("/folder1")

Results in:

12-02-21  05:06AM       <DIR>          Data
12-02-21  11:32AM       <DIR>          MoreData
12-04-21  13:03PM              13145 first.csv
12-04-21  01:01AM              13146 second.csv

I am having trouble looping through this folder- "folder1" and placing all the csv's into a dataframe. The following is the code I am currently stuck on, currently unable to even open up one file in the ftp server with a known file name:

import ftplib
with ftplib.FTP('ftpserver.com') as ftp:
    ftp.login('username','Pw')
    ftp.cwd("/folder1")
    with open("first.csv", "r") as f:
        df = pd.read_csv(f)
      
Michelle M
  • 63
  • 7

0 Answers0