commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Hufgard <christian.hufg...@gmx.de>
Subject Re: [Net] Corrupt file when using FTP
Date Mon, 04 Jul 2005 16:50:34 GMT
Hello David,

think you should set the file type before sending the file:

replace
> m_ftpClient.retrieveFile(remoteFile, out);

with
> m_ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
> m_ftpClient.retrieveFile(remoteFile, out);

Think this might work.

greets

christian



Monday, July 4, 2005, 6:42:01 PM, you wrote:


> Hello!

> I'm using FTP as described below. However, when transferring a zip file,
> although everything appears to go well with FTP (no exceptions thrown and
> all 2xx codes), when trying to open the file afterwards, I get errors such
> as:

> Error: Unexpected end of file
> Error: File corrupt


> Am I doing something wrong?


> Thanks!!!


>     public void copy(final String remotePath, final String remoteFile, final
> String localFile) throws FtpException
>     {
>         try
>         {
>             m_ftpClient.connect(m_location);
>             confirmReply();
>             login();
>             m_ftpClient.enterLocalPassiveMode();
>             confirmReply();

>             final File local = new File(localFile);
>             final OutputStream out = new FileOutputStream(local);

>             final String[] dirs = remotePath.split("/");

>             String dir;
>             for(int i = 0; i < dirs.length; i++)
>             {
>                 m_ftpClient.changeWorkingDirectory(dirs[i]);
>                 reply = m_ftpClient.getReplyCode();
>                 dir =   m_ftpClient.printWorkingDirectory();
>             }

              m_ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
>             m_ftpClient.retrieveFile(remoteFile, out);

>             confirmReply();
>             out.close();

>             m_ftpClient.logout();

>         }
>         catch(IOException e)
>         {
>             final String message = "IO Error";
>             throw new FtpException(message, e);
>         }
>         finally
>         {
>             if(m_ftpClient.isConnected())
>             {
>                 try
>                 {
>                     m_ftpClient.logout();
>                     m_ftpClient.disconnect();
>                 }
>                 catch(IOException ioe)
>                 {
>                     // do nothing
>                 }
>             }
>         }
>     }

>     private void confirmReply() throws FtpException
>     {
>         final int code = m_ftpClient.getReplyCode();

>         if(!FTPReply.isPositiveCompletion(code))
>         {
>             final String message = "Server returned code: " + code;
>             throw new FtpException(message);
>         }
>     }


> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> commons-user-help@jakarta.apache.org



-- 
Best regards,
 Christian                            mailto:christian.hufgard@gmx.de


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message