[ 
https://issues.apache.org/jira/browse/NET-409?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13038109#comment-13038109
 ] 

Jon Ericson commented on NET-409:
---------------------------------

Per your request, the following sample class demonstrates the issue.  My 
original description is not entirely accurate; it is not files over 2k in size 
that is truncated, but instead the file size "rounds down" to the nearest 1k 
and truncates the rest.

The "Declaration.txt" file used in this example is the U.S. Declaration of 
Independence.  It is 7.94KB on my local drive in Windows.  On arriving at the 
server, it is only 7K, truncating the last few sentences.

Truncation occurs when the commons-net-3.0.jar is used.  Changing the .jar on 
the class path to use the commons-net-2.2.jar, the file is transmitted in its 
entirety.

###

package com.jericson.stuff;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.FileReader;
import java.io.InputStream;
import org.apache.commons.net.ftp.FTPClient;

public class Net_409_Demo {

  /**
   * @param args
   */
  public static void main(String[] args) {
    String independence = getStringFromFile();
    FTPClient ftpClient = new FTPClient();
    try {
      ftpClient.connect("b2b.myserver.com");
      ftpClient.login("testuser", "Testpassword");
      InputStream stream = new ByteArrayInputStream(
              independence.getBytes("UTF-8"));
      ftpClient.storeFile("Independence.txt", stream);
      ftpClient.quit();
      ftpClient.disconnect();
    } catch (Exception e) {
      e.printStackTrace();
    }
    System.out.println("** Complete **");
  }

  private static String getStringFromFile() {

    /*
     * The file "Declaration.txt" begins with <Declaration>, ends with
     * </Declaration> and has no line separators in between.
     */
    try {
      BufferedReader reader = new BufferedReader(new FileReader(
              "Declaration.txt"));
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.append(reader.readLine());
      return stringBuilder.toString();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
}

###
 



> FTPClient truncates file (storeFile method)
> -------------------------------------------
>
>                 Key: NET-409
>                 URL: https://issues.apache.org/jira/browse/NET-409
>             Project: Commons Net
>          Issue Type: Bug
>          Components: FTP
>    Affects Versions: 3.0
>         Environment: Windows 7/Eclipse 3.6.2
>            Reporter: Jon Ericson
>
> Functionality works fine on commons-net-2.2.  Error occurred after upgrading 
> library to commons-net-3.0 version.  Sending a file from Windows 7 to 
> CentOS/Linux using FTPClient storeFile method results in truncation of files 
> over 2k in size.  Rolling back upgrade to commons-net-2.2 version fixes 
> problem.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to