【问题标题】:FTPSClient hangs on storeFile - file sent arrives with zero bytesFTPSClient 在 storeFile 上挂起 - 发送的文件以零字节到达
【发布时间】:2016-08-01 14:40:21
【问题描述】:

我正在使用org.apache.commons.net.ftp.FTPSClient 将文件发送到另一台服务器。但是程序在

之后挂起
boolean stored = client.storeFile(fileName, is);

文件已发送,但在服务器上它的字节数为零。

我尝试使用Filezilla 将相同的文件发送到同一台服务器,并且它可以毫无问题地传输,所以我认为这不是防火墙问题。

我还确保我的InputStream 正在通过打印文件内容来读取文件。

这是我的代码:

FTPSClient client = new FTPSClient();
InputStream is = null;

client.connect(AppValues.ftpurl);
client.login(AppValues.ftpname, AppValues.ftppass);
is = new FileInputStream("C:\\Users\\path\\filename");
boolean stored = client.storeFile(fileName, is);
System.out.println("Stored? " + stored);

从不调用存储的打印输出,并且文件以零字节到达。

我错过了什么?

【问题讨论】:

    标签: java ftp apache-commons-net


    【解决方案1】:
    FTPClient client = = new FTPClient();
    InputStream is = null;
    client.connect(AppValues.ftpurl);
    client.login(AppValues.ftpname, AppValues.ftppass);
    client.setFileType(FTP.BINARY_FILE_TYPE); 
    client.enterLocalPassiveMode();
    is = new FileInputStream("C:\\Users\\path\\filename");
    boolean stored = client.storeFile(fileName, is);
    System.out.println("Stored? " + stored);
    

    【讨论】:

    • 我使用的是 3.3 版。
    • new FileInputStream("C:\\Users\\path\\filename");你的路径对吗?
    • 就像我在帖子中所说的那样,我确保正在读取文件。所以是的。
    • 我使用 Ftp 而不是 FTPS 并获得所需的 o/p。用这两个试试!!! ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.enterLocalPassiveMode();
    • 实际上,您能否更新您的答案以在解决我的问题的评论中包含信息?目前答案中的信息不是解决方案。
    猜你喜欢
    • 1970-01-01
    • 2016-08-03
    • 2013-06-03
    • 1970-01-01
    • 1970-01-01
    • 2011-06-18
    • 1970-01-01
    • 2021-04-18
    • 1970-01-01
    相关资源
    最近更新 更多