Reputation: 4405
I want to use ftputil
instead of ftplib
in python.
On a public ftp server everything works fine with both libraries:
host = 'ftp.avm.de'
user = 'anonymous'
passwd = ''
import ftputil
with ftputil.FTPHost(host, user, passwd) as ftp:
print(ftp.getcwd(), ftp.listdir('.'))
import ftplib
with ftplib.FTP(host, user, passwd) as ftp:
print(ftp.pwd(), ftp.nlst('.'))
output:
/ ['archive', 'fritzbox', 'fritzpowerline', 'fritzwlan']
/ ['archive', 'fritzbox', 'fritzpowerline', 'fritzwlan']
If I do it on a ftp server (Windows CE6) in my local network, the output of ftputil
is empty while ftplib
correctly lists all files:
/ []
/ ['1', '2', '3']
What am i missing?
Upvotes: 0
Views: 1409
Reputation: 163
The observation above could be because of https://ftputil.sschwarzer.net/trac/ticket/110. Directories and files will be missing from the FTPHost.listdir
result if the FTP server doesn't understand the -a
option for listing hidden directories and files and interprets the option as a directory or file to list.
Try setting use_list_a_option
to False
after creating the FTPHost
instance:
ftp_host = ftputil.FTPHost(host, user, password)
ftp_host.use_list_a_option = False
# Use ftp_host as before.
...
In a future ftputil version 4.x, use_list_a_option
will default to False
to avoid this problem (see the linked ticket). I didn't want to make this change earlier in a bugfix release because this is a backward-incompatible change and may break currently working code.
Upvotes: 4