【问题标题】:Apache commons-net FTP - uploading file to Secure FTP IISApache commons-net FTP - 将文件上传到安全 FTP IIS
【发布时间】:2012-01-25 08:27:33
【问题描述】:

我正在尝试使用 Apache commons-net FTP 库将大文件 (>100Mb) 上传到 Secure FTP Server IIS。

这是我的代码:

try{
ftpClient = new FTPSClient("TLS", false);
        this.ftpClient.setDataTimeout(6000000);
        this.ftpClient.setConnectTimeout(6000000);
        ftpClient.connect(host, port);
        ftpClient.login(userName, password);
            ftpClient.enterLocalPassiveMode();
         if (ftpClient.getReplyCode() == 230){
               ftpClient.sendCommand("OPTS UTF8 ON");
               ftpClient.execPBSZ(0);
               ftpClient.execPROT("P");
         else{
             throw new Exception("connection failed.....");}
         ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
        InputStream is= new FileInputStream("C:\\movie.avi");
         ftpClient.setUseEPSVwithIPv4(true);
             ftpClient.storeFile(remotePath, is);
         is.close();
       }
         catch (SocketException e) {
    e.printStackTrace();
        } catch (IOException e) {
    e.printStackTrace();
        }

无法上传大于 19Mb 的文件。 storeFile 方法抛出 IOException 和空的 StackTrace。下面可以看到IOException变量:

   e    CopyStreamException  (id=39)    
    cause   CopyStreamException  (id=39)    
    detailMessage   "IOException caught while copying." (id=45) 
    ioException SocketException  (id=46)    
        cause   SocketException  (id=46)    
        detailMessage   "Connection reset by peer: socket write error" (id=50)  
        stackTrace  null    
    stackTrace  null    
    totalBytesTransferred   19084288    

实际上它的行为方式如下:

1) 当我开始上传时,创建了零大小的文件,而我正在上传文件大小仍然为零,当异常发生时,这个空文件被 FTP 删除。

2) 有趣的是,FileZila 也无法上传这些文件,但其大小限制为 70Mb。

我错过了什么吗?

【问题讨论】:

  • FileZilla 和您的代码会在大约相同的时间后失败吗?您是否使用其他方式(命令行 FTP 客户端等)成功上传了比这更大的文件?
  • 我尝试过超时,但它看起来一旦达到极限就会失败,在我的情况下它是 19 Mb。

标签: java ftp ftp-client apache-commons-net


【解决方案1】:

嗯。很遗憾,防火墙导致的问题,在 5 分钟超时后关闭了数据端口。

【讨论】:

    猜你喜欢
    • 2013-06-17
    • 2011-03-27
    • 2012-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-09
    • 2012-03-20
    相关资源
    最近更新 更多