gpt4 book ai didi

java - 如何在我的 FTP 服务器中实现对 EPSV (ALL) 命令的 react ?

转载 作者:行者123 更新时间:2023-11-30 05:39:57 29 4
gpt4 key购买 nike

我正在尝试通过 Wi-Fi 在本地网络上用 Java 设置 FTP 服务器。我一直在处理 EPSV ALL 命令。作为客户,我在 iPhone 上使用 VLC 播放器。当我尝试播放 .mp4 文件时,它正在向服务器发送 EPSV ALL 。服务器响应这一行:

"229 Entering Extended Passive Mode (|||" + freeDataPort + "|)"

服务器在freeDataPort上创建serverSocket,监听收入连接,但没有任何反应。

我尝试通过连接到 FileZilla 服务器来打开电影 - 它有效。另外我不明白为什么客户端在此命令(EPSV)之后尝试建立第二个连接(请求用户并再次传递的连接),而PASV命令创建数据连接并执行简单的数据传输,例如对 LIST 的响应,在第一个处理中处理。

这是我使用的 EPSV 处理程序:

private void handleEpsv() {
sendMsgToClient("229 Entering Extended Passive Mode (|||" + freeDataPort + "|)");
try {
dataSocket = new ServerSocket(freeDataPort);
System.out.println("waiting for connect... port: " + freeDataPort);
dataConnection = dataSocket.accept();
dataOutWriter = new PrintWriter(dataConnection.getOutputStream(), true);
} catch (IOException e)
{
debugOutput("Could not create data connection.");
e.printStackTrace();
}
}

上次的结果是:

FTP Server started listening on port 21
{/192.168.0.105=INITIALThread-0 Threads in data list: 0}
New connection received. Worker was created.
from INITIAL THREAD
Thread-0 - send to client: 220 Welcome to the FTP-Server

USER a from INITIAL THREAD
Thread-0 - send to client: 331 User name okay, need password

PASS a from INITIAL THREAD
Thread-0 - send to client: 230 User logged in successfully

SYST from INITIAL THREAD
Thread-0 - send to client: 215 UNIX Type: L8

PWD from INITIAL THREAD
Thread-0 - send to client: 257 "/"

TYPE I from INITIAL THREAD
Thread-0 - send to client: 200 OK

CWD // from INITIAL THREAD
Thread-0 - send to client: 250 CWD successful. / is current directory

PASV from INITIAL THREAD
Thread-0 - send to client: 227 Entering Passive Mode (192,168,0,199,7,232)

waiting for connect... port: 2024
Data connection - Passive Mode - established
LIST from INITIAL THREAD
Thread-0 - send to client: 125 Opening ASCII mode data connection for file list.

from INITIAL THREAD
Thread-0 - send to client: 226 Transfer complete.

{/192.168.0.105=INITIALThread-0 Threads in data list: 1}
New connection received. Worker was created.

Thread-1 - send to client: 220 Welcome to the FTP-Server

FEAT
Thread-1 - send to client: 211-Features:


Thread-1 - send to client: MDTM


Thread-1 - send to client: REST STREAM


Thread-1 - send to client: SIZE


Thread-1 - send to client: MLST type*;size*;modify*;


Thread-1 - send to client: MLSD


Thread-1 - send to client: UTF8


Thread-1 - send to client: CLNT


Thread-1 - send to client: MFMT


Thread-1 - send to client: EPSV


Thread-1 - send to client: EPRT


Thread-1 - send to client: 211 END

USER a
Thread-1 - send to client: 331 User name okay, need password

PASS a
Thread-1 - send to client: 230 User logged in successfully

EPSV ALL
Thread-1 - send to client: 229 Entering Extended Passive Mode (|||2025|)

used by Thread-1 Thread DATA type
waiting for connect... port: 2025

最佳答案

EPSV ALL 不是 EPSVEPSV ALL 具有特殊含义。客户端使用它来指示它将仅使用 EPSV,而不是 PASVPORTEPRT >。您应该只回复类似 200 OK 的内容。您应该阅读RFC 2428 .

实际上我从来没有见过任何FTP客户端使用这个命令。大多数服务器会忽略它或错误地处理它。 VLC 无法与您的服务器通信的原因可能是,除了响应不正确之外,您还阻止了控制连接以等待传入的数据传输。 VLC 正在发送更多命令,并在等待服务器响应时超时(因此它可能会通过打开新连接来重试)。

这是 VLC 连接到 FileZilla FTP 服务器的记录。请注意,FileZilla 也会通过响应 229 Entering Extended Passive Mode 来错误地处理 EPSV ALL。但它不会阻塞控制连接并正确处理以下命令(包括后面的EPSV)。

230 Logged on
EPSV ALL
229 Entering Extended Passive Mode (|||65079|)
TYPE I
200 Type set to I
SIZE video.avi
213 119035510
EPSV
229 Entering Extended Passive Mode (|||63465|)
TYPE I
200 Type set to I
RETR video.avi
150 Opening data channel for file download from server of "/video.avi"
...
<小时/>

实际上,即使命令是普通的 EPSV,您也不应该阻止控制连接,因为客户端将发送更多命令,特别是 RETR(或 STORLISTMLSD...)。

关于java - 如何在我的 FTP 服务器中实现对 EPSV (ALL) 命令的 react ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55856804/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com