Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5E52510CE7 for ; Sun, 5 May 2013 07:47:50 +0000 (UTC) Received: (qmail 15452 invoked by uid 500); 5 May 2013 07:47:49 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 14899 invoked by uid 500); 5 May 2013 07:47:46 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 14867 invoked by uid 99); 5 May 2013 07:47:44 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 May 2013 07:47:44 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of empaingeo@hotmail.com designates 65.55.116.105 as permitted sender) Received: from [65.55.116.105] (HELO blu0-omc3-s30.blu0.hotmail.com) (65.55.116.105) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 May 2013 07:47:38 +0000 Received: from BLU175-W23 ([65.55.116.74]) by blu0-omc3-s30.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Sun, 5 May 2013 00:47:18 -0700 X-EIP: [8H0WMuOk9m1E7Af2+bsQVgdrFh3wR8xQ] X-Originating-Email: [empaingeo@hotmail.com] Message-ID: Content-Type: multipart/alternative; boundary="_4ae27fe1-2265-493c-a584-db1ca7b0cbe5_" From: Geoffroy EMPAIN To: "user@commons.apache.org" Subject: FTPClient, resume an interrupted upload? Date: Sun, 5 May 2013 07:47:17 +0000 Importance: Normal MIME-Version: 1.0 X-OriginalArrivalTime: 05 May 2013 07:47:18.0044 (UTC) FILETIME=[C45EFDC0:01CE4964] X-Virus-Checked: Checked by ClamAV on apache.org --_4ae27fe1-2265-493c-a584-db1ca7b0cbe5_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello everyone=2C I'm currently working on an App that uploads large PDFs to a server. The ap= p works fine=2C but everytime=2C since the PDFs are so large (25MB)=2C the = upload takes a while=2C and usually after let's say 30 or 40 minutes=2C I g= et a "socketException : broken pipe". I believe that this is due to a timeo= ut or disconnect from the server (the server cuts the connection I guess)= =2C so I moved the upload routine in a loop that has a try / catch. When an= exception is thrown=2C I try to reconnect. It works fine. The upload start= s where it stopped and completes. Problem? Well=2C since the upload is "broken" in two parts (or more if any = other connection loss occurs)=2C the file uploaded is broken too! I mean th= at's definatley normal and I unerstand why that happens=2C but what I'd lik= e to know is how you can keep the upload on "hold" while trying to reconnec= t. I just want to be able to do a complete upload even if there are reconne= ctions. I want my PDF to uploaded completely. Here is the code I have : // In inputStream =3D new FileInputStream(localFile)=3B=20 // For upload loop byte[] bytesIn =3D new byte[4096]=3B int read =3D 0=3B // Loop until job is not completed (will try to reconnect if any exception = is thrown) boolean completed =3D false=3B while (!completed){ try{ // Out OutputStream outputStream =3D ftpClient.storeFileStream(remoteFile)= =3B // Transfer =20 while ((read =3D inputStream.read(bytesIn)) !=3D -1) { outputStream.write(bytesIn=2C 0=2C read)=3B transfered +=3D read=3B } // Closing streams inputStream.close()=3B outputStream.close()=3B // Final information completed =3D ftpClient.completePendingCommand()=3B if (completed) System.out.println("Done")=3B else System.out.println("Failure.")=3B completed =3D true=3B } // end try=20 catch (Exception e) { // Telling the user System.out.println("Trying to reconnect...")=3B Thread.sleep(1000)=3B // Try to reconnect ftpClient.connect(server=2C port)=3B success =3D ftpClient.login(user=2C pass)=3B if (success) { System.out.println("Connection : OK")=3B Thread.sleep(1000)=3B } else { System.out.println("Failed to connect")=3B } // Set passive mode and file type to binary ftpClient.enterLocalPassiveMode()=3B ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE)=3B } // end catch } // end loop Any help will be greatly apreciated! Thanks to the community! Best regards=3B Geoffrey = --_4ae27fe1-2265-493c-a584-db1ca7b0cbe5_--