首页 文章

FTPSClient retrievefile()挂起

提问于
浏览
1

我正在创建一个apache FTPS客户端(因为远程服务器不允许普通FTP) . 我可以毫无问题地连接和删除文件,但是当使用retrieveFile()或retrieveFileStream()时,它会挂起 .

由于某种原因,非常小的文件传输(最多5792字节),但其他任何东西都提供以下PrintCommandListener输出:

run:220 ----------欢迎使用Pure-FTPd [privsep] [TLS] ---------- 220 - 您是允许的用户数为2的50 . 220-当地时间现在是19:42 . 服务器端口:21 . 220 - 这是一个私有系统 - 没有匿名登录220-IPv6连接也欢迎在此服务器上 . 220您将在15分钟不活动后断开连接 . AUTH TLS 234 AUTH TLS好的 . USER 331用户确定 . 需要密码PASS 230 OK . 当前受限制的目录是/ TYPE A 200 TYPE现在是ASCII EPSV 229扩展被动模式OK(||| 53360 |)RETR test.txt 150-Accepted数据连接150 7.3 kbytes下载

这是代码:

try {

    FTPSClient ftpClient = new FTPSClient("tls",false);

    ftpClient.addProtocolCommandListener(new PrintCommandListener(new  PrintWriter(System.out)));

    ftpClient.connect(host, port);

    int reply = ftpClient.getReplyCode();

    if (FTPReply.isPositiveCompletion(reply)) {
        ftpClient.enterLocalPassiveMode();
        ftpClient.login(username, password);
        ftpClient.enterLocalPassiveMode();
        FileOutputStream outputStream = new FileOutputStream(tempfile);
        ftpClient.setFileType(FTPClient.ASCII_FILE_TYPE);
        ftpClient.retrieveFile("test.txt", outputStream);
        outputStream.close();
        ftpClient.logout();
        ftpClient.disconnect();
    }
} catch (IOException ioe) {
    System.out.println("FTP client received network error");
}

任何想法都非常感谢 .

1 回答

  • 0

    通常,FTPS连接的FTP命令序列(按RFC 4217AUTH TLSPBSZ 0 ,然后 USERPASS 等 . 因此您可以尝试:

    FTPSClient ftpClient = new FTPSClient("tls",false);
    ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
    ftpClient.connect(host, port);
    int reply = ftpClient.getReplyCode();
    if (FTPReply.isPositiveCompletion(reply)) {
        ftpClient.execPBSZ(0);
        reply = ftpClient.getReplyCode();
        // Check for PBSZ error responses...
        ftpClient.execPROT("P");
        reply = ftpClient.getReplyCode();
        // Check for PROT error responses...
    
        ftpClient.enterLocalPassiveMode();
    

    这明确告诉服务器不缓冲数据连接( PBSZ 0 ),并使用TLS保护数据传输( PROT P ) .

    您能够传输一些字节的事实表明问题是防火墙/路由器/ NAT的常见复杂问题,这是另一个常见的FTPS问题 .

    希望这可以帮助!

相关问题