【问题标题】:Java FTP over TLS/SSL (FTPS- Implicit) Server in Java - Several ErrorJava 中基于 TLS/SSL(FTPS- 隐式)服务器的 Java FTP - 几个错误
【发布时间】:2018-02-15 10:52:42
【问题描述】:

我正在尝试使用FTPSClient(真正的隐式)连接服务器,端口990,似乎连接正常,但它说找不到里面的文件PDF。

     String protocol = "TLS"; // TLS / SSL 
    boolean isImpicit = true; 
    int timeoutInMillis = 3000; 

    FTPSClient client = new FTPSClient(protocol, isImpicit); 

    client.setDataTimeout(timeoutInMillis); 
    client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); 

    try 
    { 
        int reply; 

        client.connect(server, port); 

        client.login(user, pass); 
        client.setFileType(FTP.BINARY_FILE_TYPE); 

        client.execPBSZ(0); 
        client.execPROT("P"); 

        System.out.println("Connected to " + server + "."); 

        reply = client.getReplyCode(); 

        if (!FTPReply.isPositiveCompletion(reply)) 
        { 
            client.disconnect(); 
            System.err.println("FTP server refused connection."); 
            System.exit(1); 
        } 

        client.listFiles(); 

        boolean retrieved = client.retrieveFile(Constantes.DIRECCION_FTP_PDF_FACTURAS + nombre_factura, new FileOutputStream(Constantes.DIRECCION_FTP_LOCAL_DESCARGAS + nombre_factura)); 

    } 
    catch (Exception e) 
    { 

        if (client.isConnected()) 
        { 
            try 
            { 
                client.disconnect(); 
            } 
            catch (IOException ex) 
            { 
                ex.printStackTrace(); 
            } 
        } 
        System.err.println("Could not connect to server."); 
        e.printStackTrace(); 
        return; 
    } 
    finally 
    { 
        System.out.println("# client disconnected"); 
        client.disconnect(); 
    } 

}

我得到的错误是 java.io.FileNotFoundException 我尝试编写自 C:\ 以来的完整路径,没有它,但没有任何效果。

有人可以帮帮我吗?

谢谢。

编辑:现在可以使用了!

【问题讨论】:

  • 您是否首先尝试使用旧的 ftp 客户端(当然兼容 FTPS...),例如 linux ftp 或 Windows 中的 FileZilla 来查看 FTPS 服务器实际呈现的内容?
  • 当然,是一个真正的服务器工作。
  • 现在 PDF 正在下载,但大小为 0 KB。
  • 如果找到文件但无法下载,则可能是主动与被动 FTP 模式的问题。

标签: java client implicit ftps


【解决方案1】:

路径“Program Files”包含一个空格,可能 FileInputStream 无法正确解析它。 可以试试把你的文件夹放到“C:/Temp/”再测试一下。

这个 FileNotFoundException 到底发生在哪里?

【讨论】:

  • 我编辑了我的代码,现在它可以工作但很糟糕。似乎下载了 PDF,但大小为 0 KB。
  • 这看起来像是其他人也已经遇到的问题:stackoverflow.com/questions/7558732/…
猜你喜欢
  • 2014-05-02
  • 2016-07-18
  • 2011-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多