Qore ssh2 Module  ..
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<auto> opts) : SftpPoller(sc, opts) {
}
nothing singleFileEvent(hash<SftpPollerFileEventInfo> 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<SftpPollerFileEventInfo> 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,
); @section sftppollerutilv1_3_1 Version 1.3.1
main SftpPoller namespace

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.4.1

  • fixed a bug registering the sftp event type (issue 4389)

Version 1.3.0

  • added support for data provider APIs

Version 1.0

  • initial release