Search code examples
javaftpftp-clientapache-commons-net

Apache commons-net FTP - uploading file to Secure FTP IIS


I'm trying to upload large file (>100Mb) using Apache commons-net FTP library to Secure FTP Server IIS.

Here is my code:

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();
        }

It fails to upload files larger then 19Mb. storeFile methods throws IOException with empty StackTrace. You can see below IOException variables:

   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    

Actually it behaves the following way:

1) when I'm starting upload, zero size file created, while I'm uploading file size is still zero and when the exception occurs, this empty file removed by FTP.

2) funny thing is that FileZila fails to upload these files as well, but its limit size is 70Mb.

Am I missing something?


Solution

  • Well. Sad by true, the problem caused by firewall, which closed Data port after 5 minutes time out.