【问题标题】:FTP Server doesn't react to USER requstFTP 服务器不响应 USER 请求
【发布时间】:2017-05-16 05:04:04
【问题描述】:

我正在尝试在 python 2.7 中制作一个基于终端的 ftp 客户端。 我设置了一个服务器(FileZilla Server 版本 0.9.41 beta)并尝试执行一个与该服务器通信的脚本。

我的客户.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 (Tim.Kosse@gmx.de)
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 (Tim.Kosse@gmx.de)
(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 user”请求? (我想在没有“socket”之外的其他库/模块的帮助下编写这个代码,(我知道 ftplib 的存在,但我不想使用它:)))

【问题讨论】:

    标签: python sockets networking ftp server


    【解决方案1】:

    尝试在USER user 之后添加\r\n

    【讨论】:

    • 成功了,非常感谢 :) 但为什么会成功呢?
    • FTP 服务器需要一个分隔符(即换行符)来知道命令何时结束。在您的情况下,USER user 是命令,您需要以 \n 结尾才能结束您的命令。
    • @HansWuast:至于“为什么”:在实现协议时需要遵循一些标准,并且 FTP 在RFC 959 中定义,所以请在那里查找为什么需要行尾。实际上只添加\n 是错误的,尽管它适用于许多服务器。正确的命令结尾不是\n,而是\r\n
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 2014-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多