Good morning,
I'm trying to get the latest file in a folder stored in a ftp. That's why I created this function :
def getDataFromCSV_FTP(fileName, index_row_to_start):
"""
Create a data frame based on the csv named fileName and located on the FTP, starting to read at the index_row_to_start
"""
try :
list_of_files = ftp.nlst(fileName) # all files with following the path with csv format
latest_file = max(list_of_files, key=os.path.getctime)
df_from_csv = pd.read_csv(latest_file, skiprows=index_row_to_start, dtype="str")
return df_from_csv
except :
print ("Error while reading the file", fileName)
The function is able to find all files on the FTP (I got the list with all files) but I'm getting an issue when it executes the max(). It's telling me that the file doesn't exist (looks like it's looking on the local path) -> FileNotFoundError: [Errno 2] No such file or directory
I'm new with python and I'm missing something here Please can someone help me to figure out what's going wrong ?
Thank you very much