commons-net-3.3 ftpClient上傳檔案報錯java.net.socketexception: connection timed out

weixin_34378969發表於2017-11-08
        FTPClient ftpClient = new FTPClient();
        FileInputStream fileInputStream;

        try {
            ftpClient.connect(HOST);
            ftpClient.login(USER_NAME, PASSWORD);
            ftpClient.enterLocalPassiveMode();
            fileInputStream = new FileInputStream(reconciliationFile);
            Boolean isSuccess = ftpClient.storeFile("/" + PATH + "/" + reconciliationFile.getName(), fileInputStream);

            logger.info("上傳取暖對賬檔案結果:{}",isSuccess.toString());

            reconciliationFile.deleteOnExit();

            return true;
        } catch (IOException e) {
            logger.info(e.getMessage(), e);
            throw new RuntimeException("FTP客戶端出錯!", e);
        }

    }

如果沒有

ftpClient.enterLocalPassiveMode();

將會丟擲異常java.net.socketexception: connection timed out
或者isSuccess的將為false;

相關文章