[Tutor] Assigning a variable to an FTP directory listing

Pat Martin wpmartin at gmail.com
Thu Dec 12 00:55:50 CET 2013


Hello,

I am writing a program that needs to pull all of the files from a
specific directory. I have a few lines written that give me the list
of files but when I try to assign it to a variable the variable ends
up equaling "226 Directory send Ok", this is a snippet of my code.

ftp=FTP(ftpserver)
ftp.login(user=username,passwd=password)
ftp.cwd(remoteworkdir)
listoffiles = ftp.retrlines('NLST')
print listoffiles
ftp.quit()

The output I get is:

sampleone
samplethree
sampletwo
226 Directory send OK.

The list of files I get is just from running the ftp.retrlines command
it isn't because of the variable printing. If I do it without the
assignment of the listoffiles variable it just lists the files from
running that command and the Directory send OK isn't there.

Any ideas on how I can assign just the list of files to a variable
that I can do a for loop to go through and download?

Thank you,

Pat


More information about the Tutor mailing list