Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
688 views
in Java FTP by (120 points)
It appears as though all I need to do is setRetryCount(>0) and setRetryDelay() and retry should be enabled? But I am trying to create a test in our code to ensure a delete is being retried without success thus far.

1) Please confirm how to enable retry

2) Please include an example how to test retrying a file transfer

Here I am simply trying to see RETRY_COUNT=3 retries take place RETRY_DELAY=5000 ms apart. The test passes without my setting the command handler, after setting the command handler I do not see any retries occur, just one failure. Is this expected?

    @Test
    public void retry() throws FTPException, IOException {

        //can use RETR for a get() STOR for a put() DELE for del()
        // Fail on DELE command.
        final int REPLY_CODE = 425; //Can't open data connection - 4xx can be retried
        RetrCommandHandler retrCommandHandler = new RetrCommandHandler();
        retrCommandHandler.setPreliminaryReplyCode(REPLY_CODE);
        fakeFtpServer.setCommandHandler(CommandNames.RETR, retrCommandHandler);

        FtpClient ftpClient = connectToServer();

        ftpClient.chdir(DATA_DIR);

        ftpClient.get(FILE1_TXT);
    }

    private FtpClient connectToServer() throws FTPException, IOException {
        DgFtpClientFactory dgFtpClientFactory = new DgFtpClientFactoryImpl();

        FtpClient ftpClient = dgFtpClientFactory.getDgFtpClient();

        ftpClient.setRetryCount(RETRY_COUNT);
        ftpClient.setRetryDelay(RETRY_DELAY);

        assertFalse(ftpClient.connected());

        ftpClient.setRemoteHost(REMOTE_HOST);
        ftpClient.setRemotePort(REMOTE_PORT);
        ftpClient.connect();
        assertTrue(ftpClient.connected());

        ftpClient.login(USER, PASSWORD);

        return ftpClient;
    }
by (120 points)
I actually am testing a get not a delete but said I was testing delete, sorry.
by (161k points)
Retry only occurs when there's a network failure during the transfer, i.e. when an IOException is thrown.

Please log in or register to answer this question.

Categories

...