Well, I don't know why this had to be harder than it currently is.
ftp = ftplib.FTP(self.get_ftp_host(), username, password)
ftp.cwd("/path/to/files/")
files = list_files(ftp)
print files
def list_files(ftp_connection):
files = []
def dir_callback(line):
bits = line.split()
if ('d' not in bits[0]):
files.append(bits[-1])
ftp_connection.dir(dir_callback)
return files
Great success!
Sources
- Upload file to FTP using Python ftplib
- ftp - Using Python's ftplib to get a directory listing, portably - Stack Overflow
- parsing - How do I parse a listing of files to get just the filenames in python? - Stack Overflow
- ftplib — FTP protocol client — Python v2.7.3 documentation
- Python ftp list only directories and not files - Stack Overflow
- upload - Python Script Uploading files via FTP - Stack Overflow
- How to upload binary file with ftplib in Python? - Stack Overflow