請嘗試以下操作。它是對原始FTP.dir
命令的修改,它使用「dir」而不是「LIST」。它給我測試過的ftp服務器提供了一個「DIR未知」的錯誤,但它確實發送了你之後的命令。 (你會想刪除我用來檢查的打印命令。)
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"')
謝謝 - 明天我可以測試一下:-) – 2008-10-16 22:57:46