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]);
}
*/
}
}
In $files you should get one line per file, containing file permissions, owner/group, filesize and filename. You will have to parse this to display them separately.
Answer: There is not a limit on the size of the file. But keep in mind that the bigger the file the longer it will take to be transferred. However, either a ReadTimeout or OutOfMemory message may appear, depending on how many files are on the ftp server, and how large the files are.
The proper steps to upload a file to FTP serverConnect and login to the server. Enter local passive mode for data connection. Set file type to be transferred to binary. Create an InputStream for the local file.
To start using FTP with Java, you will need to create a new FTPClient and then connect and login to the server using . connect(String server, int port) and . login(String username, String password) .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With