Java apache commons net ftp sendCommand返回错误的回复代码

Java apache commons net ftp sendCommand返回错误的回复代码,java,ftp,apache-commons-net,Java,Ftp,Apache Commons Net,我有一个FTP服务器,我正试图上传一个文件 在FTPClient.openDataConnection()中,我直截了当地说 if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) { return null; } 命令是“STOR”,arg是“edf0864d-1651-43b2-8453-d160bf9d0742”(我要存储的文件名) 服务器日志如下所示: PORT 86,185,26,230,213,101

我有一个FTP服务器,我正试图上传一个文件

在FTPClient.openDataConnection()中,我直截了当地说

if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) {
    return null;
}
命令是“STOR”,arg是“edf0864d-1651-43b2-8453-d160bf9d0742”(我要存储的文件名)

服务器日志如下所示:

PORT 86,185,26,230,213,101
200 Port command successful
STOR edf0864d-1651-43b2-8453-d160bf9d0742
150 Opening data channel for file upload to server of "/edf0864d-1651-43b2-8453-d160bf9d0742"
(Up to here after calling sendCommand)
PORT 86,185,26,230,213,102
200 Port command successful
从日志中,响应代码为150,但sendCommand返回的响应代码为200

其他潜在重要信息

我正在使用filezilla服务器

服务器大部分时间工作,代码完全相同。文件的初始上载工作正常,然后当我选择另一个文件覆盖第一次上载时,就会发生这种情况

接下来,还有另一个同名文件,但我以前没有遇到过这个问题

据我所知,服务器配置为被动连接,当我启动它时,它不会像以前那样对我大叫,但PASV命令会产生421无法创建套接字错误。我正在使用“活动\本地”模式

我正在使用ApacheCommonsNet3.6

如果有更多的信息可以帮助我,请告诉我

这是java的相关部分:

FTPClient ftp = new FTPClient();
String server = <server ip>;
int port = 21;
String username = <username>;
String password = <password>;
try{
    ftp.connect(server, port);
}
catch(SocketException e){
    throw new FTPCouldNotConnectException("Threw SocketException during connection", e);
}
catch(IOException e){
    throw new FTPCouldNotConnectException("Threw IOException during connection", e);
}
int reply = ftp.getReplyCode();
if(!FTPReply.isPositiveCompletion(reply)){
    try{
        ftp.disconnect();
        throw new FTPCouldNotConnectException("Reply Code: " + reply + ", Could not connect");
    }
    catch(IOException e){
        throw new FTPCouldNotConnectException(
                "Threw IOException during disconnection after failing to connect with reply code: " + reply,
                e);
    }
}
else{
    try{
        if(ftp.login(username, password)){
            LOGGER.info("Successfully logged in to ftp server");
            ftp.setFileTransferMode(org.apache.commons.net.ftp.FTP.STREAM_TRANSFER_MODE);
            ftp.setFileStructure(org.apache.commons.net.ftp.FTP.FILE_STRUCTURE);
            ftp.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
            ftp.enterLocalActiveMode();
        }
        else{
            LOGGER.warn("Failed to log in to ftp server");
        }
    }
    catch(IOException e){
        throw new FTPCouldNotConnectException("Failed to log in to server, threw ioexception", e);
    }
}
try{
    ftp.storeFile("edf0864d-1651-43b2-8453-d160bf9d0742", new FileInputStream("test.jpg"));
}
catch(IOException e){
    LOGGER.error("java.io.IOException caught", e);
}
FTPClient ftp=新的FTPClient();
字符串服务器=;
int端口=21;
字符串用户名=;
字符串密码=;
试一试{
ftp.connect(服务器、端口);
}
捕获(SocketException e){
抛出新的FTPCouldNotConnectException(“连接期间抛出的SocketException”,e);
}
捕获(IOE异常){
抛出新的FTPCouldNotConnectException(“连接期间抛出IOException”,e);
}
int reply=ftp.getReplyCode();
如果(!FTPReply.isPositiveCompletion(回复)){
试一试{
ftp.disconnect();
抛出新的FTPCouldNotConnectException(“回复代码:“+Reply+”,无法连接”);
}
捕获(IOE异常){
抛出新的FTPCouldNotConnectException(
连接失败后,在断开连接期间引发IOException,回复代码:“+reply,
e) );
}
}
否则{
试一试{
if(ftp.login(用户名、密码)){
info(“成功登录到ftp服务器”);
setFileTransferMode(org.apache.commons.net.ftp.ftp.STREAM_TRANSFER_MODE);
setFileStructure(org.apache.commons.net.ftp.ftp.FILE_结构);
setFileType(org.apache.commons.net.ftp.ftp.BINARY_FILE_TYPE);
ftp.enterLocalActiveMode();
}
否则{
LOGGER.warn(“未能登录到ftp服务器”);
}
}
捕获(IOE异常){
抛出新的FTPCouldNotConnectException(“登录服务器失败,抛出ioexception”,e);
}
}
试一试{
ftp.storeFile(“edf0864d-1651-43b2-8453-d160bf9d0742”,新文件输入流(“test.jpg”);
}
捕获(IOE异常){
LOGGER.error(“java.io.IOException-capture”,e);
}

我找到答案的依据是,第一次调用代码工作正常,但第二次调用失败


在java代码中,我没有调用FTPClient.completePendingCommand(),它是,导致后续调用出现意外行为。

请添加更多代码请准确添加您使用的库及其版本。添加java代码和库版本使用Wireshark捕获两种情况下的FTP流量并向我们展示。添加Wireshark捕获