WatchDir (watch a directory)¶
function WatchDir(path: string, recursive: boolean)
This RemoteWatcher method adds a directory/folder to the list of directories/folders “watched” by the remote file system watcher.
The path
parameter specifies a directory path to be watched.
The recursive
parameter specifies whether or not the RemoteWatcher should also watch all sub-folders of the specified folder.
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;
}