我有一个FTP服务器,我试图在FTPClient上传一个文件apache commons net ftp sendCommand返回错误的回复代码
。 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无法创建套接字错误。我使用ACTIVE_LOCAL模式
我使用的净阿帕奇百科全书3.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);
}
请添加更多代码 – Grzesiek
请准确添加您使用的库及其版本。 – Grzesiek
添加了java代码和库版本 –