Events (polling for)

function Events(): []WatcherEvent

WatcherEvent = {
  TimeStamp: Date   // timestamp of when the event happened
  Event:     string // watcher event as string: CREATE, REMOVE, MODIFY
  Object:    string // the remote object (file/directory) affected by Event
}

This RemoteWatcher method is designed to be called within the scope of an endless loop, to keep the script running forever (unless terminated by an admin or an OS signal). Each time this method is called, it returns an array of pending, to-be-handled, file system notifications.

Every call to this method will also clear the pending notifications, so all events that are left un-handled will not be notified again.

Example:

{
  ConsoleFeedback = true;
  var scli = new SftpClient();
  scli.Host = 'your.sftpserver.com:22';
  scli.User = 'some_username';
  scli.PassFromSecret = 'name_of_the_secret_password';
  if (scli.Connect()) {
    watchr = new RemoteWatcher(scli);
    watchr.WatchDir('/Docs', true);
    watchr.NotifyRemove = false;
    watchr.InclusionFilter = ['*.docx', '*.xlsx']
    watchr.ExclusionFilter = ['some_private_document.docx']
    watchr.Start();
    while (true) {
      Sleep(30000);
      if (HaltSignalReceived()) {
        break;
      }
      evt = watchr.Events()
      if (evt.length > 0) {
        for (var i = 0; i < evt.length; i++) {
          if (evt[i].Event == 'CREATE') {
            scli.DownloadWithPath(evt[i].Object, 'C:\\MyLocalCopies', 0);
          }
        }
      }
    }
    scli.Close();
  }
  scli = null;
}