由于多种原因,我们想使用pycurl
来获取MLST command上FTP服务器上存储的文件的信息。
使用以下代码,我们几乎可以满足需求:
# More or less equivalent to: curl --list -X MLST -D /tmp/headers ftp://ftp.ncbi.nlm.nih.gov/genomes/genbank/archaea/assembly_summary.txt
import pycurl
try:
from io import BytesIO
except ImportError:
from StringIO import StringIO as BytesIO
c = pycurl.Curl()
c.setopt(c.URL,r'ftp://ftp.ncbi.nlm.nih.gov/genomes/genbank/archaea/assembly_summary.txt')
c.setopt(pycurl.DIRLISTONLY,True)
# Use MLST
c.setopt(c.CUSTOMREQUEST,"MLST")
# Write header to buffer
output = BytesIO()
c.setopt(pycurl.HEADERFUNCTION,output.write)
# Perform request
c.perform()
# Print header
result = output.getvalue()
result = result.decode('ISO-8859-1')
perform()
失败,出现CURLE_FTP_COULDNT_RETR_FILE,但result
(标题)包含了我们所需的内容。如果尝试使用CLI版本,则返回代码也是CURLE_FTP_COULDNT_RETR_FILE,但是文件/tmp/headers
包含数据。
我们认为这与MLST
使用控制连接而不是数据连接有关。
有什么想法吗?
编辑1
如果没有DIRLISTONLY
(这很奇怪),我们还没有找到一种获取结果的方法。另外,如果我们使用NOBODY
,我们将无法获得答案。
编辑2
事实证明,result
包含有关目录(ftp://ftp.ncbi.nlm.nih.gov/genomes/genbank/archaea/
)的信息,而不是文件,因此此处的代码不正确。