Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.net.SocketTimeoutException:读取FTPClient.listFiles时超时_Java - Fatal编程技术网

java.net.SocketTimeoutException:读取FTPClient.listFiles时超时

java.net.SocketTimeoutException:读取FTPClient.listFiles时超时,java,Java,我试图使用ApacheCommonsNetFTPSClient在FTP服务器上列出CurrentWorkingDirectory中的文件,代码如下。我能够使用WinSCP成功连接和下载文件 FTPSClient client = new FTPSClient(true); client.setDefaultTimeout(defaultTimeout); client.setConnectTimeout(connectTimeout);

我试图使用ApacheCommonsNetFTPSClient在FTP服务器上列出CurrentWorkingDirectory中的文件,代码如下。我能够使用WinSCP成功连接和下载文件

        FTPSClient client = new FTPSClient(true);
        client.setDefaultTimeout(defaultTimeout);
        client.setConnectTimeout(connectTimeout);
        client.setDataTimeout(dataTimeout);
        
        client.connect(server, 990);
        int replyCode = client.getReplyCode();
        if (!FTPReply.isPositiveCompletion(replyCode)){
            LOG.error("Unable to connect to server. Error Text=" + client.getReplyString());
        }
        
        if (localActive) {
            setLocalActiveMode();
        } else {
            setLocalPassiveMode();
        }
        
        boolean status = client.login(user, password);
        if (!status) {
            replyCode = client.getReplyCode();
            LOG.error("Login failed. Error Text=" + client.getReplyString());
        }
        setBinaryMode(binaryMode);
        client.changeWorkingDirectory(path);
        
        FTPFile[] files = client.listFiles();
        for (FTPFile file : files) {
提出的例外情况是:

java.net.SocketTimeoutException: Read timed out
   at java.net.SocketInputStream.socketRead0(Native Method)
   at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
   at java.net.SocketInputStream.read(SocketInputStream.java:171)
   at java.net.SocketInputStream.read(SocketInputStream.java:141)
   at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
   at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
   at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
   at java.io.InputStreamReader.read(InputStreamReader.java:184)
   at java.io.BufferedReader.fill(BufferedReader.java:161)
   at java.io.BufferedReader.readLine(BufferedReader.java:324)
   at java.io.BufferedReader.readLine(BufferedReader.java:389)
   at org.apache.commons.net.ftp.FTPFileEntryParserImpl.readNextEntry(FTPFileEntryParserImpl.java:53)
   at org.apache.commons.net.ftp.FTPListParseEngine.readStream(FTPListParseEngine.java:128)
   at org.apache.commons.net.ftp.FTPListParseEngine.readServerList(FTPListParseEngine.java:104)
   at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3302)
   at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3271)
   at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2930)
   at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2977)


我将保护缓冲区大小设置为0并使用了专用数据连接(下面的代码&它工作了) client.execPBSZ(0);
客户。执行保护(“P”)

是的,WinSCP和Java代码在同一台机器上