5

I had written a java program to copy a file (*.dmp) format from our server into FTP server. The program is working fine and it's copying the file into ftp directory.

But only problem there is a bit file size difference after i copy to FTP. My source file size is 2.47 GB. When i compare the file size in MB's , in FTP server the size is increased by 16 MB. I had done twice and the it's showing same behaviour. But when i copy manually into FTP directory(withour java program), the file sizes are exact.

Am i doing any thing wrong. Below is my java program

    package dev.test;

import java.io.*;
import java.io.IOException;
import java.net.SocketException;
import org.apache.commons.net.ftp.*;
public class FTPTest {

      public static void main(String a[]) throws SocketException, IOException
      {
      FTPClient f= new FTPClient();
    f.connect("10.100.8.74");
    boolean flag =f.login("dspetrofac\\admin","admin");
    System.out.println(" is connected ::"+flag);

    // change working directory of FTP Server

    boolean isDirectoryChanged =f.changeWorkingDirectory("IT/Documentum Team/");

    System.out.println(" Is the working directory Changed :: "+isDirectoryChanged);



    // to copy from source to FTP

    InputStream inputFile = new FileInputStream(new File("\\\\dmt500aaashjuae\\testDumpAutomation\\testSiteDump.dmp"));
    boolean isSaved = f.storeFile("testSiteDump.dmp", inputFile);
    System.out.println("is File Saved in FTP Server :: "+isSaved);
    /*
      String list[] =f.listNames();
    for(int i=0;i<list.length;i++)
    {
      System.out.println(" file no"+i+":: "+list[i]);
    }

    */

      }
}
JavaGeek
  • 1,535
  • 9
  • 39
  • 63
  • 1
    Look at http://stackoverflow.com/questions/3145768/transfer-raw-binary-with-apache-commons-net-ftpclient – svaor Nov 03 '11 at 07:58

1 Answers1

10

You need to call setFileType( FTP.BINARY_FILE_TYPE) - otherwise any CR / LF / CR + LF gets translated (due to ASCII mode in FTP protocol being the default of the used implementation) and thus changes the file content/size.

Yahia
  • 69,653
  • 9
  • 115
  • 144