【问题标题】:List files with pyftp - proftpd vs. pyftpdlib behavior使用 pyftp 列出文件 - proftpd 与 pyftpdlib 行为
【发布时间】:2015-09-26 07:14:15
【问题描述】:

我有一个测试代码,它使用带有 pyftpdlib 的 FTP 存根,令我惊讶的是,它在生产中失败了。这样做的原因是proftpd 返回目录名称以响应NLST。这是来自pyftpdlib FTP stub 的回复:

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

【问题讨论】:

  • 如果 'structuredata_advanced' 不是当前目录,服务器应该返回路径名 'structuredata_advanced' 前缀。使用con.pwd() 检查当前目录。

标签: python ftp proftpd pyftpdlib


【解决方案1】:

我是uftpd的作者。

我只是在谷歌上搜索了一下,不久前发现DJB wrote aboute this,不幸的是,服务器之间的输出似乎不同。

我的解释是;建议在给定目录中的每个输出文件前加上目录名。即,如果客户端发送“NLST dir”,服务器应该回复:

dir/a
dir/b

而是像这样简单地输出目录dir/中的文件:

a
b

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-17
    • 1970-01-01
    • 2015-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多