how to make the file uploading to ftp faster

Currently we are using  below code to upload files to the FTP folder?
basically 60 MB file is taking 2.5 minutes to upload to the ftp server.Is there any way to make it faster?

at this line client.storeFile(filename, fis) its taking maximum time.

Manually when we upload(drag) a file to FTP folder through filezilla then it's not taking this much time.

In this approach itself ,Can we split the file and send it in parallel and upload it to ftp?will this approach be faster?if yes Please send some links.

Instead of this approach Can we suggest to client that instead of uploading files to ftp server,Can you copy the files to common network path(shared mapping network drive)?will it be faster compared to FTP?What do you sugest?

FTPClient client = new FTPClient();
FileInputStream fis = null;

try {
    client.connect("ftp.domain.com");
    client.login("admin", "secret");

    //
    // Create an InputStream of the file to be uploaded
    //
    String filename = "sample.zip";
    fis = new FileInputStream(filename);

    //
    // Store file to server
    //
    client.storeFile(filename, fis);
    client.logout();
} catch (IOException e) {
    e.printStackTrace();
} finally {
    try {
        if (fis != null) {
            fis.close();
        }
        client.disconnect();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Open in new window

chaituu chaituAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
We don't know what API you're using
0
chaituu chaituAuthor Commented:
java.io.* and apache commons
0
krakatoaCommented:
Maybe look at increasing the send and or receive buffer sizes. Maybe.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

raj3060Commented:
0
gobinath rajuCommented:
FTPClient ftpClient = new FTPClient();
                        try {
                            ftpClient.connect(servername, port);
                            ftpClient.login(username, password);
                            ftpClient.enterLocalPassiveMode();

                            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
                           // File sourceFile = new File("file which you want to send");
                            InputStream inputStream = new FileInputStream("/home/gobinath/Desktop/file1/"+files);

                            boolean done = ftpClient.storeFile("dest", inputStream);
                            inputStream.close();
                            if (done) {
                                  System.out.println("file is uploaded successfully..............");
                            }

                        } catch (IOException e) {
                              System.out.println("Exception occured while ftp : "+e);
                        } finally {
                            try {
                                if (ftpClient.isConnected()) {
                                    ftpClient.logout();
                                    ftpClient.disconnect();
                                }
                            } catch (IOException e) {
                                  System.out.println ("Exception occured while ftp logout/disconnect : "+e);
                            }
                        }
0
chaituu chaituAuthor Commented:
raju,

written same code.
0
gobinath rajuCommented:
those 2 lines are missing,
  ftpClient.enterLocalPassiveMode();

  ftpClient.setFileType(FTP.BINARY_FILE_TYPE);


   using this code  ,

FTPClient ftpClient = new FTPClient();
                        try {
                            ftpClient.connect(servername, port);
                            ftpClient.login(username, password);
                            ftpClient.enterLocalPassiveMode();

                            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
                           // File sourceFile = new File("file which you want to send");
                            InputStream inputStream = new FileInputStream("/home/gobinath/Desktop/file1/"+files);

                            boolean done = ftpClient.storeFile("dest", inputStream);
                            inputStream.close();
                            if (done) {
                                  System.out.println("file is uploaded successfully..............");
                            }

                        } catch (IOException e) {
                              System.out.println("Exception occured while ftp : "+e);
                        } finally {
                            try {
                                if (ftpClient.isConnected()) {
                                    ftpClient.logout();
                                    ftpClient.disconnect();
                                }
                            } catch (IOException e) {
                                  System.out.println ("Exception occured while ftp logout/disconnect : "+e);
                            }
                        }
0
chaituu chaituAuthor Commented:
same code here as well.howmuch time is it taking for you if you upload for 2 GB file?
0
chaituu chaituAuthor Commented:
existing code running for the past 2 yrs only problem is slowness.
0
AndyAinscowFreelance programmer / ConsultantCommented:
Using a faster internet connection will probably help as well.
1
nociSoftware EngineerCommented:
60MB / 150 seconds = 0.4MB/s or ~3.2Mbps
So depending on your bandwidth it might be the best you can achieve.
(Latency is another issue, also hampering logon logout sequences.)...

maybe lookinto the curl library can help ( https://curl.haxx.se ) it consists of a commandline tool and an API.
That API  has quite some control over specific paramters.

In general it may help to have large buffers for reading & writing. as large a window as possible on the session.
It might help if IO can be overlapped (read & write data asynchronously)   The will greatly improve latency issues.
so not read 1 -> send 1 -> read 2 -> send 2 ... but more like two tasks one filling buffers from file and the other sending data ...
Assuming send also needs to wait for an ACK.

read 1 -> read 2 -> read 3 -> read 4
                 send 1 -> send 2 -> send 3
(this might need heavy modification of underlying code).

Also don't login/logout every time to send a file, logon once, and send a bulk of files. one after the other.
(running more than one session may be an option as well, not speeding up one file, but it will utilize bandwidth better.)

Depending on bandwidht / CPU speed ratio's and the compressability of data, compressing data before transmitting might help a lot.

Then again why use FTP... for authentication it requires to send password over the line unencrypted. so it's to easy to pickup data.  (Just a wireshark filter on port 21 will be sufficient).
scp might be preferable.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gr8gonzoConsultantCommented:
If you use FileZilla vs. Java, you might be dealing with a different connection that has different upload speeds. noci pointed out that you're getting an upstream of almost 1/2 megabyte per second (3.2Mbps), which is a fairly common upstream speed for some internet connections. If you're turning around and uploading from a different connection with a larger upstream speed, then you'll get it done faster.

Also, the server's own downstream bandwidth will make a difference here. For example, if the server has a 30 Mbps downstream link and it's receiving 10 files from different users at once, then the transfer speed is going to be reduced overall.
0
gr8gonzoConsultantCommented:
The author indicated gobinth's comment did not help. I'd recommend noci's comment as the most relevant:
#42500362
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.