Qore SftpPoller Module Reference  1.1
SftpPoller Module

Introduction to the SftpPoller Module

The SftpPoller module implements an abstract class that will poll a remote directory with the SFTP protocol and return matching files.

To use this class, subclass the SftpPoller class and implement the SftpPoller::SftpPoller::singleFileEvent() and SftpPoller::SftpPoller::postSingleFileEvent() methods.

SftpPoller Module Examples

The following simple example will poll for files and then print out information for the files polled (as well as all info, detail, and debug messages) and exit immediately:

%requires ssh2
%requires SftpPoller
class MySftpPoller inherits SftpPoller {
constructor(SFTPClient sc, hash opts) : SftpPoller(sc, opts) {
}
nothing singleFileEvent(hash fh) {
printf("GOT FILE: %y\n", fh - "data" + ("data_type": fh.data.type(), "data_size": fh.data.size()));
# in this case, the polling stop operation will take effect after all the singleFileEvent() calls are made for the polling operation
stopNoWait();
}
nothing postSingleFileEvent(hash fh) {
}
}
code info = sub (string msg) { printf("INFO: %s\n", msg); };
code detail = sub (string msg) { printf("DETAIL: %s\n", msg); };
code debug = sub (string msg) { printf("DEBUG: %s\n", msg); };
hash opts = (
"log_info": info,
"log_detail": detail,
"log_debug": debug,
);
SftpClient sc("sftp://user@pass:localhost");
SftpPoller poller(sc, opts);
poller.waitStop();

Note that SftpPoller::stopNoWait() was called in the event thread because calling SftpPoller::stop() in the event thread would cause an exception to be thrown.

A useful poller class would implement the SftpPoller::singleFileEvent() method which process already-transferred files and the SftpPoller::postSingleFileEvent() by deleting / moving / renaming the files so that they would not be acquired on the next poll.

SftpPoller Module in Sandboxed Programs

The SftpPoller class includes support for running in sandboxed Program objects with the following parse options set:

SftpPoller Module Release Notes

Version 1.0

  • initial release