Well, I don't know why this had to be harder than it currently is.
01.
ftp
=
ftplib.FTP(
self
.get_ftp_host(), username, password)
02.
ftp.cwd(
"/path/to/files/"
)
03.
files
=
list_files(ftp)
04.
print
files
05.
06.
def
list_files(ftp_connection):
07.
files
=
[]
08.
09.
def
dir_callback(line):
10.
bits
=
line.split()
11.
12.
if
(
'd'
not
in
bits[
0
]):
13.
files.append(bits[
-
1
])
14.
15.
ftp_connection.dir(dir_callback)
16.
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