我有一个测试代码,它使用带有pyftpdlib的FTP存根,令我惊讶的是,它在生产中失败了。原因是proftpd响应NLST返回目录名。下面是来自pyftpdlib FTP存根的响应:
In [10]: local_conn.login('user', '12345')
Out[10]: '230 Login successful.'
In [11]: import ftplib
In [12]: local_conn = ftplib.FTP()
In [13]: local_conn.connect('localhost', 2121)
Out[13]: '220 pyftpdlib 1.4.0 ready.'
In [14]: local_conn.login('user', '12345')
Out[14]: '230 Login successful.'
In [15]: local_conn.nlst('structuredata_advanced')
Out[15]:
['Report_20150618.csv',
'Report_20150618.fin',
'Report_20150619.csv',
'Report_20150619.fin',
'Report_20150620.csv',
'Report_20150620.fin']以下是来自proftpd的响应
In [16]: remote_conn = ftplib.FTP()
In [17]: remote_conn.connect('A1B.7Y.XX.XX', 21)
Out[17]: '220 ProFTPD 1.3.4a Server (vztd3.company.com) [A1B.7Y.XX.XX]'
In [18]: remote_conn.login('remoteuser', 'verysecret')
Out[18]: '230 User yougov logged in'
In [19]: remote_conn.nlst('structuredata_advanced')
Out[19]:
['structuredata_advanced/Report_20150624.csv',
'structuredata_advanced/Report_20150629.csv',
'structuredata_advanced/Report_20150625.fin',
'structuredata_advanced/Report_20150628.fin',
'structuredata_advanced/Report_20150627.fin',
'structuredata_advanced/Report_20150620.fin',
'structuredata_advanced/Report_20150619.csv',
...]很容易删除这些目录名:
# this code works both in production and testing
files = conn.nlst(basedir)
# proftd is weired it returns the basedir name too
files = [f.split('/')[-1] for f in files]但是我想了解一下pyftpdlib做错了什么吗?
这是可以在ProFTPD中配置的吗?
关于FTP协议和NLST命令,我需要知道些什么吗?
更新
我刚刚测试了另一个名为uftpd的ftp服务器,它在发出NLST时的行为类似于pyftpdlib。
发布于 2015-07-12 19:30:41
我是uftpd的作者。
我只是在谷歌上搜索了一下,结果发现DJB写了这个在一段时间前就出现了,不幸的是,服务器之间的输出似乎有所不同。
不过,我的解释是:建议不要在给定目录中的每个输出文件前加上目录名。也就是说,如果客户端发送'NLST dir‘,服务器不应该回复:
dir/a
dir/b但是,只需输出目录dir/中的文件,如下所示:
a
bhttps://stackoverflow.com/questions/31291617
复制相似问题