使用Apache commons的Java FTP抛出"复制时捕获到IOException"

时间:2015-07-20 11:56:40

标签: java apache javafx ftp apache-commons-fileupload

我制作了一个JavaFX应用程序,其中包括将大文件(> 1GB)上传到服务器。每次我在同一个地方得到同样的错误。任何建议我在这里做错了什么。

column1 is null

现在在FTPHandler类

null

每次我上传文件(文件都是不同类型的文件,如.iso,.dat等)时,前几个文件(上传序列就像前几百个文件一样小,即少于几MB,那么前10个文件是超过1 GB大)将成功上传(即所有较小的文件和最后10个文件中的2个),但当它开始上传第三个大文件时,我得到以下异常。

ftpclient.connect(server, port);
ftpclient.login(ftpuser, ftppass);
ftpclient.enterLocalPassiveMode();
ftpclient.setKeepAlive(true);
ftpclient.setControlKeepAliveTimeout(3000);

Task<Void> copyMnt = new Task<Void>() {
@Override
protected Void call(){
  try {                              
      new Thread(new FTPHandler(ftpclient, source , dest)).run();
  } catch (IOException ex) {
     Logger.getLogger(MyAppController.class.getName()).log(Level.SEVERE, null, ex); 
  }
 return null;
  }
};


new Thread(copyMnt).start();

1 个答案:

答案 0 :(得分:0)

CopyStreamException有“原因”异常。使用.getCause()检查一下,看看出了什么问题。

请参阅Util.copyStream method

public static final long copyStream(InputStream source, OutputStream dest,
                                    int bufferSize, long streamSize,
                                    CopyStreamListener listener,
                                    boolean flush)
throws CopyStreamException
{
    int bytes;
    long total = 0;
    byte[] buffer = new byte[bufferSize >= 0 ? bufferSize : DEFAULT_COPY_BUFFER_SIZE];

    try
    {
        while ((bytes = source.read(buffer)) != -1)
        {
             ....
        }
    }
    catch (IOException e)
    {
        throw new CopyStreamException("IOException caught while copying.",
                                      total, e);
    }

    return total;
}

uploadSingleFile功能的某处,执行

try
{
     ftpClient.storeFile(...)
}
catch (Exception e)
{
     e.printStackTrace();
     if (e.getCause() != null)
     { 
         e.getCause().printStackTrace();
     }
}

我不懂Java,所以代码可能不是100%正确。

另见Getting full string stack trace including inner exception