Implementing Retry feature in SFTP

  • Charanjith A C
    Charanjith A C

    Hello guys,


    The SFTP stack does not have an option to set timeout for a command.

    Changes that I made:

    1) In SftpMessageStore, setResponseTimeout() has been added to set the timeout passed by user.
    2) In SftpMessageStore, I have modified the getMessage() method to use this timeout value, instead of waiting indefinitely. The current stack in wob just sleeps every 5 seconds and expects someone to help out.
    3) Even after sufficient wait time if I am not getting any response from the server I am throwing an exception, which will be caught by the actual client to retry the last command again.

    For implementing this I included a responseTimeout variable in SftpMessageStore and the method 'getMessage' is changed as follows :-

        public synchronized SubsystemMessage getMessage(UnsignedInteger32 requestId)
            throws InterruptedException, IOException {
            Iterator it;
            SubsystemMessage msg;
            //Getting the expiration time. (current time + response timeout)
            Date expiration = responseTimeout == 0
            ? null : new Date(new Date().getTime() + (responseTimeout
            // If there ae no messages available then wait untill there are.
            while (getState().getValue() == OpenClosedState.OPEN) {
                if (messages.size() > 0) {
                    it = messages.iterator();

                    while (it.hasNext()) {
                        msg = (SubsystemMessage);

                        if (msg instanceof MessageRequestId) {
                            if (((MessageRequestId) msg).getId().equals(requestId)) {

                                return msg;
                log.debug("Waiting for new messages");
                //If expiration has happened throw Response Timeout
                if (expiration != null && expiration.before(new Date())){
                    throw new IOException("Response Timeout occured");

            return null;

    Is there any anticipated or known issues here?