I have a requirement when I need to pull the latest files from an FTP folder, the problem is that the file name has spaces, and the file name has a specific pattern. Below is the code that I executed:
import sys from ftplib import FTP import os import socket import time import pandas as pd import numpy as np from glob import glob import datetime as dt from __future__ import with_statement ftp = FTP('') ftp.login('','') ftp.cwd('') ftp.retrlines('LIST') filematch='*Elig.xlsx' downloaded = [] for filename in ftp.nlst(filematch): fhandle=open(filename, 'wb') print 'Getting ' + filename ftp.retrbinary('RETR '+ filename, fhandle.write) fhandle.close() downloaded.append(filename) ftp.quit()
I understand that I can add an empty list to the ftp.dir () command, but since the file name has spaces, I can not split it correctly and select the last file of the type that I outlined above.
Any help would be great.
Manas jani
source share