1

非常に具体的な (非標準の) 文字列を FTP サーバーに送信する必要があります。

dir "SYS:\IC.ICAMA."

引用のスタイルとその内容と同様に、ケースは重要です。

残念ながら、ftplib.dir() は 'dir' ではなく 'LIST' コマンドを使用しているようです (このアプリケーションでは間違ったケースを使用しています)。

FTP サーバーは実際には電話交換機であり、非常に非標準的な実装です。

ftplib.sendcmd() を使用してみましたが、コマンド シーケンスの一部として「pasv」も送信されます。

FTP サーバーに特定のコマンドを発行する簡単な方法はありますか?

4

1 に答える 1

4

以下を試してください。FTP.dir「LIST」の代わりに「dir」を使用する元のコマンドの変更です。テストした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-16T20:28:12.400 に答える