commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Leangen" <dlean...@canada.com>
Subject [Net] Corrupt file when using FTP
Date Mon, 04 Jul 2005 16:42:01 GMT

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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message