title: SftpInboundFileSynchronizer not synchronizing
body: <p>I have the following SFTP file synchronizer:</p>
  
  <pre><code>@Bean
  public SftpInboundFileSynchronizer sftpInboundFileSynchronizer() {
      SftpInboundFileSynchronizer fileSynchronizer = new SftpInboundFileSynchronizer(sftpSessionFactory());
      fileSynchronizer.setDeleteRemoteFiles(false);
      fileSynchronizer.setRemoteDirectory(applicationProperties.getSftpDirectory());
      CompositeFileListFilter&lt;ChannelSftp.LsEntry&gt; compositeFileListFilter = new CompositeFileListFilter&lt;ChannelSftp.LsEntry&gt;();
      compositeFileListFilter.addFilter(new SftpPersistentAcceptOnceFileListFilter(store, "sftp"));
      compositeFileListFilter.addFilter(new SftpSimplePatternFileListFilter(applicationProperties.getLoadFileNamePattern()));
      fileSynchronizer.setFilter(compositeFileListFilter);
      fileSynchronizer.setPreserveTimestamp(true);
      return fileSynchronizer;
  }
  </code></pre>
  
  <p>When the application first runs, it synchronizes to the local directory with the remote SFTP site directory. However, it fails to pick up any subsequent changes in the remote SFTP directory files. </p>
  
  <p>It is scheduled to poll as follows:</p>
  
  <pre><code>@Bean
  @InboundChannelAdapter(autoStartup="true", channel = "sftpChannel", poller = @Poller("pollerMetadata"))
  public SftpInboundFileSynchronizingMessageSource sftpMessageSource() {
      SftpInboundFileSynchronizingMessageSource source =
              new SftpInboundFileSynchronizingMessageSource(sftpInboundFileSynchronizer());
      source.setLocalDirectory(applicationProperties.getScheduledLoadDirectory());
      source.setAutoCreateLocalDirectory(true);
      ChainFileListFilter&lt;File&gt; chainFileFilter = new ChainFileListFilter&lt;File&gt;();
      chainFileFilter.addFilter(new LastModifiedFileListFilter());
      FileSystemPersistentAcceptOnceFileListFilter fs = new FileSystemPersistentAcceptOnceFileListFilter(store, "dailyfilesystem");
      fs.setFlushOnUpdate(true);
      chainFileFilter.addFilter(fs);
      source.setLocalFilter(chainFileFilter);
      source.setCountsEnabled(true);
      return source;
  }
  
  @Bean
  public PollerMetadata pollerMetadata(RetryCompoundTriggerAdvice retryCompoundTriggerAdvice) {
      PollerMetadata pollerMetadata = new PollerMetadata();
      List&lt;Advice&gt; adviceChain = new ArrayList&lt;Advice&gt;();
      adviceChain.add(retryCompoundTriggerAdvice);
      pollerMetadata.setAdviceChain(adviceChain);
      pollerMetadata.setTrigger(compoundTrigger());
      pollerMetadata.setMaxMessagesPerPoll(1);
      return pollerMetadata;
  }
  
  @Bean
  public CompoundTrigger compoundTrigger() {
      CompoundTrigger compoundTrigger = new CompoundTrigger(primaryTrigger());
      return compoundTrigger;
  }
  
  @Bean
  public CronTrigger primaryTrigger() {
      return new CronTrigger(applicationProperties.getSchedule());
  }
  
  @Bean
  public PeriodicTrigger secondaryTrigger() {
      return new PeriodicTrigger(applicationProperties.getRetryInterval());
  }
  </code></pre>
  
  <p>In the <code>afterReceive</code> method of <code>RetryCompoundTriggerAdvice</code> which extends <code>AbstractMessageSourceAdvice</code>, I get a null result after the first run. </p>
  
  <p>How can I configure the synchronizer such that it synchronizes periodically (rather than just once at app startup)?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I have found that when the SFTP site has no file in its directory on my application startup, the <code>SftpInboundFileSynchronizer</code> syncs at every polling interval. So I can see <code>com.jcraft.jsch</code> log statements at every poll. But as soon as a file is found on the SFTP site, it syncs to get that file locally and then syncs no more.</p>
  
  <p><strong>Update 2</strong></p>
  
  <p>My apologies... here's the custom code:</p>
  
  <pre><code>@Component
  public class RetryCompoundTriggerAdvice extends AbstractMessageSourceAdvice {
  
      private final static Logger logger = LoggerFactory.getLogger(RetryCompoundTriggerAdvice.class);
  
      private final CompoundTrigger compoundTrigger;
  
      private final Trigger override;
  
      private final ApplicationProperties applicationProperties;
  
      private final Mail mail;
  
      private int attempts = 0;
  
      private boolean expectedMessage;
      private boolean inProcess;
  
      public RetryCompoundTriggerAdvice(CompoundTrigger compoundTrigger, 
              @Qualifier("secondaryTrigger") Trigger override, 
              ApplicationProperties applicationProperties,
              Mail mail) {
          this.compoundTrigger = compoundTrigger;
          this.override = override;
          this.applicationProperties = applicationProperties;
          this.mail = mail;
      }
  
      @Override
      public boolean beforeReceive(MessageSource&lt;?&gt; source) {
          logger.debug("!inProcess is " + !inProcess);
          return !inProcess;
      }
  
      @Override
      public Message&lt;?&gt; afterReceive(Message&lt;?&gt; result, MessageSource&lt;?&gt; source) {
  
          if (expectedMessage) {
              logger.info("Received expected load file. Setting cron trigger.");
              this.compoundTrigger.setOverride(null);
              expectedMessage = false;
              return result;
          }
  
          final int  maxOverrideAttempts = applicationProperties.getMaxFileRetry();
  
          attempts++;
          if (result == null &amp;&amp; attempts &lt; maxOverrideAttempts) {
              logger.info("Unable to find file after " + attempts + " attempt(s). Will reattempt");
              this.compoundTrigger.setOverride(this.override);
          } else if (result == null &amp;&amp; attempts &gt;= maxOverrideAttempts) {
              String message = "Unable to find daily file" + 
                      " after " + attempts + 
                      " attempt(s). Will not reattempt since max number of attempts is set at " + 
                      maxOverrideAttempts + "."; 
              logger.warn(message);
              mail.sendAdminsEmail("Missing Load File", message);
              attempts = 0;
              this.compoundTrigger.setOverride(null);
          } else {
              attempts = 0;
              // keep periodically checking until we are certain
              // that this message is the expected message
              this.compoundTrigger.setOverride(this.override);
              inProcess = true;
              logger.info("Found load file");
          }
          return result;
      }
  
      public void foundExpectedMessage(boolean found) {
          logger.debug("Expected message was found? " + found);
          this.expectedMessage = found;
          inProcess = false;
      }
  
  }
  </code></pre>