英文:
Java FTPSClient TLS FTP connection to pureftp server hangs on storeFile
问题
以下是您提供的代码部分的翻译:
我尝试使用以下Java代码将文件存储在pureftp服务器上,使用org.apache.commons.net.ftp库。
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPSClient;
public void upload2ndToServer(String directory) throws Exception {
// ...(代码的其余部分)
}
public void upload(File src, FTPSClient ftp) throws IOException {
// ...(代码的其余部分)
}
关于日志部分,这是您的日志内容:
如您所见,此过程登录并创建一个目录,但在尝试将一个37KB大小的文件存储在该新目录中时挂起。进程在“150 Accepted data connection”响应之后挂起,无法完成。
2020-09-08 14:14:36,330 DEBUG [restartedMain] com.jahtoe.pes.PROCESS: upload /home/vmdovs/Two
// ...(日志的其余部分)
2020-09-08 16:07:18 64919 1 Command: PROT P
// ...(日志的其余部分)
2020-09-08 16:11:58 64919 3 Response: 226-1 Kbytes used (0%) - authorized: 10240000 Kb
// ...(日志的其余部分)
2020-09-08 16:11:58 64919 3 Status: File transfer successful, transferred 37 B in 1 second
// ...(日志的其余部分)
关于Filezilla日志,以下是您提供的部分内容:
2020-09-08 16:07:22 64919 1 Response: 226-Options: -a -l
// ...(日志的其余部分)
如果您有任何问题或需要进一步的帮助,请随时问我。
英文:
I'm trying to store a file on a pureftp server using the following java code using org.apache.commons.net.ftp
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.commons.net.ftp.FTPSClient;
public void upload2ndToServer(String directory) throws Exception {
LOG.debug("upload2ndToServer " + directory);
FTPSClient ftp = new FTPSClient("TLS", false);
int reply;
ftp.connect(GetConfigValue("2nd", "RemoteAddress"));
ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
throw new Exception("Exception in connecting to FTP Server");
}
ftp.login(GetConfigValue("2nd", "RemoteLogin"), GetConfigValue("2nd", "RemotePassword"));
LOG.debug("FTP info: " + ftp.getStatus() + " : " + " : " + ftp.getReplyString());
ftp.changeWorkingDirectory(GetConfigValue("2nd", "RemoteDirectory"));
ftp.setFileType(FTP.BINARY_FILE_TYPE);
ftp.setControlEncoding("UTF8");
ftp.execPBSZ(0);
ftp.execPROT("P");
try {
upload(new File(directory), ftp);
} catch (Exception e) {
ftp.disconnect();
LOG.info("ERROR FTP disconnected: " + e.getMessage());
}
}
public void upload(File src, FTPSClient ftp) throws IOException {
LOG.debug("upload " + src.getPath());
if (src.isDirectory()) {
LOG.debug("directory " + src.getName());
ftp.makeDirectory(src.getName());
ftp.changeWorkingDirectory(src.getName());
for (File file : src.listFiles()) {
upload(file, ftp);
}
ftp.changeToParentDirectory();
} else {
InputStream input = null;
try {
ftp.enterLocalPassiveMode();
LOG.debug("FTP info: " + ftp.getStatus() + " : " + " : " + ftp.getReplyString());
BufferedInputStream buffIn = null;
buffIn = new BufferedInputStream(new FileInputStream(src.getPath()));
boolean result = ftp.storeFile(src.getName(), buffIn);
buffIn.close();
LOG.debug(result + " stored file " + src.getName() + " code:" + ftp.getReplyCode());
LOG.debug("reply" + ftp.getReplyString());
} finally {
IOUtils.close(input);
}
}
}
As you can see from the log, the process logs in and creates a directory, however it then hangs on trying to store a 37KB file in that new directory. The process hangs after '150 Accepted data connection' as a response and does not complete.
2020-09-08 14:14:36,330 DEBUG [restartedMain] com.jahtoe.pes.PROCESS: upload /home/vmdovs/Two
2020-09-08 14:14:36,331 DEBUG [restartedMain] com.jahtoe.pes.PROCESS: directory Two
MKD Two
257-"Two" : The directory was successfully created
257 1 Kbytes used (0%) - authorized: 10240000 Kb
CWD Two
250 OK. Current directory is /_admin_/lsi/provincelcddsds1/Two
2020-09-08 14:14:37,439 DEBUG [restartedMain] com.jahtoe.pes.PROCESS: upload /home/vmdovs/Two/test.txt.gz
STAT
211 http://www.pureftpd.org/
2020-09-08 14:14:37,874 DEBUG [restartedMain] com.jahtoe.pes.PROCESS: FTP info: 211 http://www.pureftpd.org/
: : 211 http://www.pureftpd.org/
PASV
227 Entering Passive Mode (9,9,9,9,9,9)
STOR test.txt.gz
150 Accepted data connection
Filezilla Log:
2020-09-08 16:07:14 64919 1 Status: Connecting to 9.9.9.9:21...
2020-09-08 16:07:15 64919 1 Status: Connection established, waiting for welcome message...
2020-09-08 16:07:15 64919 1 Response: 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
2020-09-08 16:07:15 64919 1 Response: 220-You are user number 8 of 100 allowed.
2020-09-08 16:07:15 64919 1 Response: 220-Local time is now 10:07. Server port: 21.
2020-09-08 16:07:15 64919 1 Response: 220-This is a private system - No anonymous login
2020-09-08 16:07:15 64919 1 Response: 220-IPv6 connections are also welcome on this server.
2020-09-08 16:07:15 64919 1 Response: 220 You will be disconnected after 480 minutes of inactivity.
2020-09-08 16:07:15 64919 1 Command: AUTH TLS
2020-09-08 16:07:16 64919 1 Response: 234 AUTH TLS OK.
2020-09-08 16:07:16 64919 1 Status: Initializing TLS...
2020-09-08 16:07:17 64919 1 Status: Verifying certificate...
2020-09-08 16:07:17 64919 1 Status: TLS connection established.
2020-09-08 16:07:17 64919 1 Command: USER vince
2020-09-08 16:07:17 64919 1 Response: 331 User vince OK. Password required
2020-09-08 16:07:17 64919 1 Command: PASS **********
2020-09-08 16:07:18 64919 1 Response: 230-OK. Current directory is /
2020-09-08 16:07:18 64919 1 Response: 230 1 Kbytes used (0%) - authorized: 10240000 Kb
2020-09-08 16:07:18 64919 1 Command: SYST
2020-09-08 16:07:18 64919 1 Response: 215 UNIX Type: L8
2020-09-08 16:07:18 64919 1 Command: FEAT
2020-09-08 16:07:18 64919 1 Response: 211-Extensions supported:
2020-09-08 16:07:18 64919 1 Response: EPRT
2020-09-08 16:07:18 64919 1 Response: IDLE
2020-09-08 16:07:18 64919 1 Response: MDTM
2020-09-08 16:07:18 64919 1 Response: SIZE
2020-09-08 16:07:18 64919 1 Response: REST STREAM
2020-09-08 16:07:18 64919 1 Response: MLST type*;size*;sizd*;modify*;UNIX.mode*;UNIX.uid*;UNIX.gid*;unique*;
2020-09-08 16:07:18 64919 1 Response: MLSD
2020-09-08 16:07:18 64919 1 Response: AUTH TLS
2020-09-08 16:07:18 64919 1 Response: PBSZ
2020-09-08 16:07:18 64919 1 Response: PROT
2020-09-08 16:07:18 64919 1 Response: UTF8
2020-09-08 16:07:18 64919 1 Response: ESTA
2020-09-08 16:07:18 64919 1 Response: PASV
2020-09-08 16:07:18 64919 1 Response: EPSV
2020-09-08 16:07:18 64919 1 Response: SPSV
2020-09-08 16:07:18 64919 1 Response: 211 End.
2020-09-08 16:07:18 64919 1 Command: OPTS UTF8 ON
2020-09-08 16:07:18 64919 1 Response: 200 OK, UTF-8 enabled
2020-09-08 16:07:18 64919 1 Command: PBSZ 0
2020-09-08 16:07:19 64919 1 Response: 200 PBSZ=0
2020-09-08 16:07:19 64919 1 Command: PROT P
2020-09-08 16:07:19 64919 1 Response: 200 Data protection level set to "private"
2020-09-08 16:07:19 64919 1 Status: Logged in
2020-09-08 16:07:19 64919 1 Status: Retrieving directory listing...
2020-09-08 16:07:19 64919 1 Command: PWD
2020-09-08 16:07:19 64919 1 Response: 257 "/" is your current location
2020-09-08 16:07:19 64919 1 Command: TYPE I
2020-09-08 16:07:20 64919 1 Response: 200 TYPE is now 8-bit binary
2020-09-08 16:07:20 64919 1 Command: PASV
2020-09-08 16:07:20 64919 1 Response: 227 Entering Passive Mode (9,9,9,9,9,9)
2020-09-08 16:07:20 64919 1 Command: MLSD
2020-09-08 16:07:21 64919 1 Response: 150 Accepted data connection
2020-09-08 16:07:22 64919 1 Response: 226-Options: -a -l
2020-09-08 16:07:22 64919 1 Response: 226 37 matches total
2020-09-08 16:07:22 64919 1 Status: Directory listing of "/" successful
2020-09-08 16:11:57 64919 3 Command: TYPE I
2020-09-08 16:11:57 64919 3 Response: 200 TYPE is now 8-bit binary
2020-09-08 16:11:57 64919 3 Command: PASV
2020-09-08 16:11:57 64919 3 Response: 227 Entering Passive Mode (18,213,82,97,156,117)
2020-09-08 16:11:57 64919 3 Command: STOR test.txt.gz
2020-09-08 16:11:57 64919 3 Response: 150 Accepted data connection
2020-09-08 16:11:58 64919 3 Response: 226-1 Kbytes used (0%) - authorized: 10240000 Kb
2020-09-08 16:11:58 64919 3 Response: 226-File successfully transferred
2020-09-08 16:11:58 64919 3 Response: 226 0.047 seconds (measured here), 0.76 Kbytes per second
2020-09-08 16:11:58 64919 3 Status: File transfer successful, transferred 37 B in 1 second
2020-09-08 16:11:58 64919 3 Status: Retrieving directory listing of "/2nd"...
2020-09-08 16:11:58 64919 3 Command: PASV
2020-09-08 16:11:58 64919 3 Response: 227 Entering Passive Mode (9,9,9,9,9,9)
2020-09-08 16:11:58 64919 3 Command: MLSD
2020-09-08 16:11:59 64919 3 Response: 150 Accepted data connection
2020-09-08 16:11:59 64919 3 Response: 226-Options: -a -l
2020-09-08 16:11:59 64919 3 Response: 226 5 matches total
Does anyone have a suggestion as how to resolve this issue?
Can you explain what the filezilla log line 226-Options: -a -l means?
Regards
Conteh
答案1
得分: 0
原来,如果我将依赖关系从
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.7</version>
切换到
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
然后,它按预期工作。
英文:
It turns out that if I switch the dependency from
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.7</version>
</dependency>
to
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
</dependency>
It then works as expected.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论