Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.5k views
in Java FTP by
I have implements the EventListener interface and register the listener to ftpClient, now I have a question:
When uploading a big file, if the server is down during the download, before the ftpClient throws an exception,
the uploadStarted method and uploadCompleted in EventListener has benn called for twice.

In my opinion, if there is an exception during the upload, the uploadCompleted method in EventListener should not be called.

Thanks a lot.

9 Answers

0 votes
by (162k points)
Best to post the DEBUG log, or at least the relevant portions of it.

uploadCompleted is passed the exception if the upload fails. It is always called by design.
0 votes
by
I have just download the latest version and import the source code into my projcect
Please notice the following code in FTPClient.java from Line 2598

private String putStream(InputStream srcStream, String remoteFile, boolean append)
        throws IOException, FTPException {

        try {        
            if (monitorEx != null)
                monitorEx.transferStarted(TransferDirection.UPLOAD, remoteFile);   
            remoteFile = putData(srcStream, remoteFile, append);
            validateTransfer();
            uploadCount++;
        }
        catch (FTPException ex) {
            throw ex;
        }
        catch (ControlChannelIOException ex) {
            throw ex;       
        }
        catch (IOException ex) {
            validateTransferOnError(ex);
            throw ex;        
        }
        finally {
            if (monitorEx != null)
                monitorEx.transferComplete(TransferDirection.UPLOAD, remoteFile);   
        }
        return remoteFile;
    }

Please notice the last finally block, which call transferComplete even an exception is catched during the transfer.
In fact, after I turn down the ftp server by force during transfer, an IOException is caught, but due to the finally block, the listener's transferComplete is called.
0 votes
by
I have read the javadoc of EventListener,which says:

/**
     * Notifies that an upload has completed
     * 
     * @param connID Identifier of FTP connection
     * @param remoteFilename   remote file name
     */
    public void uploadCompleted(String connId, String remoteFilename);


So I wonder if an excetpion is caught during an upload, uploadCompleted should not been called.
0 votes
by (162k points)
It is called to keep code consistent, but should have had the exception passed into the method. Unfortunately it's a bit late to change the interface.
0 votes
by
So, can I say this is a bug ? Any plan to fix it ?

I think this should be fixed bucause EventListener is the only way to monitor the whole transfer proecess.
0 votes
by (162k points)
We can't change the interface of the EventListener but if you have any suggestions, we'd welcome them.
0 votes
by
How about change
        finally { 
            if (monitorEx != null) 
                monitorEx.transferComplete(TransferDirection.UPLOAD, remoteFile);    
        }

into
if (monitorEx != null) 
                monitorEx.transferComplete(TransferDirection.UPLOAD, remoteFile);    

So when any exception is caught, monitorEx's transferComplete will not be called.

And another bug: why the transferComplete method is called twice? I check the source, find that when transfer is
interrupted, FTPClient will automatically retry the transfer, so transferComplete is called twice. I find this is effected by
constant DEFAULT_RETRY_COUNT in FTPClient.

These two bugs have a great influence on the accuracy of monitoring, So I think these bugs should be fixed.

Thanks for your reading.
0 votes
by (162k points)
Many thanks for your feedback. We'll look at addressing the second problem - I'm not quite sure about the first problem yet, as it will be altering the default behaviour and might impact a lot of users.
0 votes
by
I think the first problem is quite important: All user's transfer monitor class which implements EventListener will not work correctly que to the bug.

Categories

...