PythonでFTPサーバのファイル一覧を取得できない
実現したいこと
下記に示すPC-BからPC-Aに接続してPC-AのFTPサーバのファイル一覧を取得したい。
環境について
PC-A:
- Windows10 Pro
- Python v3.10.5
- FTP Server = FileZilla Server 1.5.1
- FTP Client = FileZilla v3.60.2
PC-B:
- Windows10 Pro
- Python v3.10.5
- FTP client = FileZilla v3.60.2
実行したことと得られたエラー
PC-AでFileZilla Serverを起動してから、PC-Bでコマンドプロンプトを開き、以下のように記述しました。IPアドレスとパスワードは適当です。
Python3
1import ftplib 2 3with ftplib.FTP() as ftp: 4 ftp.connect(host="111.222.333.444",port=21) 5 ftp.login(user="ftp_user",passwd="hogehoge") 6 ftp.cwd("/")
ここまで入力してリターンを押すと、
CommandPrompt
1220 FileZilla Server 1.5.1 2220 Welcome to FTP Server 3230 Login successful. 4250 CWD command successful
となって、FTPサーバへ接続できているように思われます。しかし、次に、
Python3
1files = ftp.nlst(".")
を実行すると、
Error
1Traceback 2File "<stdin>", line 1, in <module> 3File "C:\Wpy64-3105\lib\ftplib.py" line 553, in nlst 4 self.retrlines(cmd, files.append) 5File "C:\Wpy64-3105\lib\ftplib.py" line 461, in retrlines 6 resp = self.sendcmd('TYPE A') 7File "C:\Wpy64-3105\lib\ftplib.py" line 280, in sendcmd 8 self.putcmd(cmd) 9File "C:\Wpy64-3105\lib\ftplib" in 207, in putcmd 10 self.putline(line) 11File "C:\Wpy64-3105\lib\ftplib.py" in 202, in putline 12 self.sock.sendall(line.encode(self.encoding)) 13AttrbuteError : 'NoneType' object has no attribute "sendall"
が出力されます。
しかし、PC-Bにて、FileZillaを起動し、接続すると、普通にファイル一覧が表示されるのです。
python3でFTPサーバへ接続する際、
Python3
1with ftplib.FTP(encoding="cp932") as ftp: 2with ftplib.FTP(encoding="utf-8") as ftp:
のような記述も試しましたが、同じエラーが出力されてダメでした。
PC-A側のファイヤーウォールは受信/送信ともにできるように穴を開けてあります。
そうすれば、エラーがなくなってファイル一覧を取得できるようになるのでしょうか。
アドバイスよろしくお願いします。
FileZilla Serverの管理コンソールはどうやって出すのでしょうか。
Administration Interface -FileZilla Server 1.5.1-という窓は出るのですが、この中に、設定画面に入れるコマンドはありません。
回答1件
あなたの回答
tips
プレビュー