m_ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

David Leangen 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.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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to