次のようなコードがあります。
host = ftputil.FTPHost("ftp.example.com","anonymous","")
try:
os.mkdir('./ftp.example.com')
except:
traceback.print_exc()
else:
sys.stderr.write('WTF?')
for root,dirs,files in host.walk('/Path/to/a/lot/of/census/data/files/',topdown=True,onerror=None):
for filename in files:
fullpath = os.path.join(root,filename)
#print fullpath,host.lstat(fullpath)[6],int(host.lstat(fullpath)[8])
try:
host.download_if_newer(fullpath,'./ftp.example.com/'+filename,callback=None)
except:
traceback.print_exc()
しばらくすると、以下のような例外が端末画面のフラッディングを開始します。
*cmd* 'PWD'
*resp* '257 "/Path/to/a/lot/of/census/data/files/xx"'
*cmd* u'CWD /Path/to/a/lot/of/census/data/files/xx'
*resp* '257 "/Path/to/a/lot/of/census/data/files/xx"'
*cmd* u'TYPE I'
*resp* '250 Directory successfully changed.'
*cmd* 'PASV'
*resp* '200 Switching to Binary mode.'
Traceback (most recent call last):
File "bdpublicdata.py", line 56, in <module>
host.download_if_newer(fullpath,'./ftp.example.com/'+filename,callback=None)
File "/usr/local/lib/python2.7/dist-packages/ftputil/host.py", line 521, in download_if_newer
callback=callback)
File "/usr/local/lib/python2.7/dist-packages/ftputil/file_transfer.py", line 176, in copy_file
source_fobj = source_file.fobj()
File "/usr/local/lib/python2.7/dist-packages/ftputil/file_transfer.py", line 91, in fobj
return self._host.open(self.name, self.mode)
File "/usr/local/lib/python2.7/dist-packages/ftputil/host.py", line 204, in open
encoding=encoding, errors=errors, newline=newline)
File "/usr/local/lib/python2.7/dist-packages/ftputil/file.py", line 194, in _open
self._conn = self._session.transfercmd(command)
File "/usr/local/lib/python2.7/dist-packages/ftputil/error.py", line 168, in __exit__
raise FTPIOError(*exc_value.args)
FTPIOError: 200 Switching to Binary mode.
Debugging info: ftputil 3.1, Python 2.7.6 (linux2)
*cmd* 'PWD'
*resp* '227 Entering Passive Mode (126,218,41,23,59,181)'
Traceback (most recent call last):
File "bdpublicdata.py", line 56, in <module>
host.download_if_newer(fullpath,'./ftp.example.com/'+filename,callback=None)
File "/usr/local/lib/python2.7/dist-packages/ftputil/host.py", line 521, in download_if_newer
callback=callback)
File "/usr/local/lib/python2.7/dist-packages/ftputil/file_transfer.py", line 176, in copy_file
source_fobj = source_file.fobj()
File "/usr/local/lib/python2.7/dist-packages/ftputil/file_transfer.py", line 91, in fobj
return self._host.open(self.name, self.mode)
File "/usr/local/lib/python2.7/dist-packages/ftputil/host.py", line 181, in open
host = self._available_child()
File "/usr/local/lib/python2.7/dist-packages/ftputil/host.py", line 159, in _available_child
host._session.pwd()
File "/usr/lib/python2.7/ftplib.py", line 587, in pwd
return parse257(resp)
File "/usr/lib/python2.7/ftplib.py", line 855, in parse257
raise error_reply, resp
error_reply: 227 Entering Passive Mode (126,218,41,23,59,181)
また、ホストからディレクトリ ツリー全体を取得することはできません。
何かご意見は?