2017-01-02 22 views
2

私は、Python 2.7でターミナルベースのFTPクライアントを作成しようとしています。 サーバー(FileZilla Serverバージョン0.9.41ベータ版)をセットアップし、そのサーバーと通信するスクリプトを実行しようとしました。FTPサーバーがUSER要求に反応しません

マイClient.py:

import socket 
import time 

host = raw_input("ip ->") 
port = 21 

s = socket.socket() 

s.connect((host, port)) 

print s.recv(8192) 
print s.recv(8192) 

s.send("USER user") 
print "sent" 
print s.recv(512) 

s.close() 

Client.py出力:

ip ->localhost 
220-FileZilla Server version 0.9.41 beta 

220-written by Tim Kosse ([email protected]) 
220 Please visit http://sourceforge.net/projects/file 

sent 
421 Login time exceeded. Closing control connection. 

サーバー出力:

(000010)02.01.2017 03:45:22 - (not logged in) (127.0.0.1)> Connected, sending welcome message... 
(000010)02.01.2017 03:45:22 - (not logged in) (127.0.0.1)> 220-FileZilla Server version 0.9.41 beta 
(000010)02.01.2017 03:45:22 - (not logged in) (127.0.0.1)> 220-written by Tim Kosse ([email protected]) 
(000010)02.01.2017 03:45:22 - (not logged in) (127.0.0.1)> 220 Please visit http://sourceforge.net/projects/filezilla/ 
(000010)02.01.2017 03:46:22 - (not logged in) (127.0.0.1)> 421 Login time exceeded. Closing control connection. 
(000010)02.01.2017 03:46:22 - (not logged in) (127.0.0.1)> disconnected. 

はなぜサーバは、私の "USERユーザー" の要求を無視するのですか? (私はftplibの存在を認識していますが、私はそれを使用したくありません:))

答えて

1

試してみてくださいUSER userの後に\r\nを追加します。

+0

それはトリックでした、ありがとうございます:) しかし、それはなぜ機能しましたか? –

+0

FTPサーバは、コマンドがいつ終了するかを知るために区切り文字(A改行)を必要とします。あなたの場合は、 'USER user'がコマンドです。コマンドを終了するには' \ n'で終わる必要があります。 –

+0

@ HansWuast: '理由'について:プロトコルを実装する際に必要な標準があり、FTPは[RFC 959](https://www.ietf.org/rfc/rfc959.txt)で定義されていますので、なぜあなたは行末が必要なのか調べてください。実際に '\ n'を追加するだけでは間違っていますが、多くのサーバで動作します。コマンドの正しい終わりは '\ n'ではなく' \ r \ n'です。 –

関連する問題