我需要向FTP服务器发送一个非常特定的(非标准)字符串:
dir "SYS:\IC.ICAMA."这种情况很关键,引文的风格和内容也是如此。
不幸的是,ftplib.dir()似乎使用的是'LIST‘命令,而不是'dir’(并且它在此应用程序中使用了错误的大小写)。
FTP服务器实际上是一个电话交换机,它是一个非常非标准的实现。
我尝试使用ftplib.sendcmd(),但它也将'pasv‘作为命令序列的一部分发送。
有没有向FTP服务器发出特定命令的简单方法?
发布于 2008-10-16 20:28:12
尝试以下操作。这是对原始FTP.dir命令的修改,该命令使用“目录”而不是“列表”。在我测试它的ftp服务器上,它给出了一个"DIR不能理解“的错误,但它确实发送了你想要的命令。(您可能希望删除我用来检查它的print命令。)
import ftplib
class FTP(ftplib.FTP):
def shim_dir(self, *args):
'''List a directory in long form.
By default list current directory to stdout.
Optional last argument is callback function; all
non-empty arguments before it are concatenated to the
LIST command. (This *should* only be used for a pathname.)'''
cmd = 'dir'
func = None
if args[-1:] and type(args[-1]) != type(''):
args, func = args[:-1], args[-1]
for arg in args:
if arg:
cmd = cmd + (' ' + arg)
print cmd
self.retrlines(cmd, func)
if __name__ == '__main__':
f = FTP('ftp.ncbi.nih.gov')
f.login()
f.shim_dir('"blast"')https://stackoverflow.com/questions/210067
复制相似问题