Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Big file to FTP

807580Dec 17 2009 — edited Dec 23 2009
Hi there -

I'm attempting to upload VERY large files via FTP (300 mb to up to 5 gb or so) and I'm using the following code:
 FileInputStream fis = null;
        FTPClient client = new FTPClient();

        
        try {

            
            client.connect("ftpserver.com");
            
            if (client.login("username", "password"))  {
                System.out.println("login successful");
            } else {
                System.out.println("cant login");
            }
          
            String filename = "very_large_video_file.mov";

            try {

                fis = new FileInputStream(filename);

                client.storeFile(filename, fis);

                client.logout();

                fis.close();

                System.out.println("Upload complete.");

            } catch (Exception e) {

                System.out.println("Error..."+e.getLocalizedMessage());

            }

        } catch (SocketException ex) {

            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

        } catch (IOException ex) {

            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

        }
This code does work, however with very large files it appears to upload them all (I only tested with a 400 mb file and the entire file uploaded) however then my JAR just hangs. When I force quit the JAR is get a "Java Result: 2147483647". After Googling that I found that it's a heap overflow error which tells me that the file is too large. How do I go about uploading these extremely large files? I'm using Apache Commons FTPClient.

Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 20 2010
Added on Dec 17 2009
12 comments
446 views