0

我正在尝试使用以下java代码使用org.apache.commons.net.ftp将文件存储在pureftp服务器上

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);
        }
    }
}

正如您从日志中看到的那样,该进程登录并创建了一个目录,但是它会继续尝试在该新目录中存储一个 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 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 日志:

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

有人对如何解决此问题提出建议吗?

您能解释一下 filezilla 日志行226-Options: -a -l 的含义吗?

问候康泰

4

1 回答 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>

然后它按预期工作。

于 2020-09-27T09:34:12.283 回答