Qore SftpPoller Module Reference
1.3
|
SftpPoller client class implementation. More...
Public Member Methods | |
constructor (Qore::SSH2::SFTPClient n_sftp, hash< auto > nconf) | |
creates the SftpPoller object from the SFTPClient argument and configuration hash argument passed More... | |
constructor (hash< auto > nconf) | |
creates the SftpPoller object from the configuration hash argument passed More... | |
destructor () | |
stops the polling operation if in progress and destroys the object | |
int | getPollCount () |
returns the current poll count | |
int | getStoreFile (string remote_path, string local_path, *timeout n_timeout) |
retrieves a remote file and stores it to a local path More... | |
string | getTextFile (string path, *timeout n_timeout, *string n_encoding) |
retrieves a text file and returns the file's contents | |
binary | getFile (string path, *timeout n_timeout) |
retrieves a binary file and returns the file's contents | |
rename (string old, string nnew, *timeout n_timeout) | |
renames a file on the server | |
removeFile (string fn, *timeout n_timeout) | |
deletes a file on the server | |
*hash< Qore::SSH2::Ssh2StatInfo > | stat (string path, *timeout n_timeout) |
returns information about a remote file (see Qore::SSH2::SFTPClient::stat() for a description of the return format) | |
checkRemotePath (string path, bool write=False, *timeout n_timeout) | |
check if a remote path is writable More... | |
list< hash< SftpPollerFileEventInfo > > | getFiles (int sort=SftpPoller::SortNone, int order=SftpPoller::OrderAsc) |
returns a list of regular file hashes matching any file name mask set for the object More... | |
int | start () |
starts polling in the background; returns the thread ID of the polling thread More... | |
stopNoWait () | |
stops the polling operation, returns immediately More... | |
stop () | |
stops the polling operation, returns when the polling operation has been stopped More... | |
waitStop () | |
waits indefinitely for the polling operation to stop; if polling was not in progress then this method returns immediately More... | |
startInline () | |
starts the polling operation inline (not in a background thread) More... | |
bool | runOnce () |
runs a single poll (useful for checking for errors inline before starting a background thread) | |
*bool | fileEvent (list< hash< SftpPollerFileEventInfo >> l) |
called for each poll with a list of all files matched before transfer; if this method returns False or nothing, then the singleFileEvent method is not called | |
abstract | singleFileEvent (hash< SftpPollerFileEventInfo > fih) |
called for each matching file individually whenever matching files are polled with the list of matching file names; if any error occurs here, the error is logged and the polling operation is retried More... | |
abstract | postSingleFileEvent (hash< SftpPollerFileEventInfo > fih) |
called after singleFileEvent() for each matching file individually whenever matching files are polled with the list of matching file names; if any error occurs here, the polling operation stops More... | |
Static Public Member Methods | |
static | checkPath (string path, string type, bool write=False) |
checks a path on the local file system More... | |
Public Attributes | |
const | OrderAsc = 0 |
ascending sort order | |
const | OrderDesc = 1 |
descending sort order | |
const | SortNone = 0 |
no sorting | |
const | SortName = 1 |
sort by name | |
const | RequiredKeys |
minimum required keys for all constructors | |
const | RequiredKeysWithHost = RequiredKeys + "host" |
RequiredKeys for the constructor(hash) without an Qore::SSH2::SFTPClient argument. | |
const | Defaults |
default values for constructor hash argument | |
const | OptionalKeys |
optional constructor hash keys | |
const | AllKeys = RequiredKeysWithHost + Defaults.keys() + OptionalKeys |
all keys | |
const | ErrorDelay = 1m |
pause when SFTP errors are detected | |
Private Member Methods | |
Mutex | m () |
start mutex | |
Counter | sc () |
stop counter | |
logInfo (string fmt) | |
calls the "log_info" closure or call reference with important information | |
logDetail (string fmt) | |
calls the "log_detail" closure or call reference with detail information | |
logDebug (string fmt) | |
calls the "log_debug" closure or call reference with verbose debugging information | |
setMask () | |
converts a glob mask into a regex | |
sftpSleep (softint secs) | |
sleeps for the specificed number of seconds | |
run () | |
starts the polling operation | |
Private Attributes | |
string | host |
host or address name | |
int | port |
port | |
string | user |
user | |
string | url |
url | |
*string | pass |
password; one of "pass" or "keyfile" *must* be set | |
*string | keyfile |
path to the ssh private key in PEM format; one of "pass" or "keyfile" *must* be set | |
softlist< string > | path = "." |
path(s) to poll | |
string | rootSftpPath |
path after connect to SFTP server | |
*string | mask |
file glob name mask (ignored if "regex_mask" also set) | |
int | poll_interval |
poll interval in seconds | |
bool | runflag = False |
run flag | |
bool | get_files |
internal "get files" flag | |
bool | fatal = False |
internal fatal error flag | |
int | pollcnt = 0 |
internal poll counter | |
int | tid |
polling tid | |
timeout | timeout |
timeout in ms | |
Qore::SSH2::SFTPClient | sftp |
SFTPClient object. | |
int | reopts = 0 |
file matching regex options | |
*softint | minage |
minimum file age | |
*string | encoding |
file encoding for text files | |
*code | log_info |
optional info log closure | |
*code | log_detail |
optional detail log closure | |
*code | log_debug |
optional debug log closure | |
*code | start_thread |
optional start thread closure | |
*code | sleep |
optional sleep closure | |
bool | binary |
binary transfer flag (for singleFileEvent()) | |
bool | writable |
chech if path is writable for others in constructor | |
string | check_file |
name of check writable file | |
*bool | skip_file_content_retrieval |
whether or not to skip the file content retrieval in runOnce() | |
SftpPoller client class implementation.
|
static |
checks a path on the local file system
DIR-ERROR | this exception is thrown if the local path does not exist, is not readable, is not a directory, or should be writable and is not |
SftpPoller::SftpPoller::checkRemotePath | ( | string | path, |
bool | write = False , |
||
*timeout | n_timeout | ||
) |
check if a remote path is writable
REMOTE-DIR-ERROR | this exception is thrown if the remote path does not exist, is not a directory, or is not not writable |
SftpPoller::SftpPoller::constructor | ( | Qore::SSH2::SFTPClient | n_sftp, |
hash< auto > | nconf | ||
) |
creates the SftpPoller object from the SFTPClient argument and configuration hash argument passed
n_sftp | the new SFTPClient object |
nconf | a hash with the following optional keys:
|
SFTPPOLLER-CONSTRUCTOR-ERROR | missing required key, invalid port or poll_interval given |
SFTPCLIENT-PARAMETER-ERROR | empty hostname passed |
SOCKET-CONNECT-ERROR | error establishing socket connection (no listener, port blocked, etc); timeout establishing socket connection |
SSH2CLIENT-CONNECT-ERROR | no user name set; ssh2 or libssh2 error |
SSH2-ERROR | error initializing or establishing ssh2 session |
SSH2CLIENT-AUTH-ERROR | no proper authentication method found |
SFTPCLIENT-CONNECT-ERROR | error initializing sftp session or getting remote path |
SftpPoller::SftpPoller::constructor | ( | hash< auto > | nconf | ) |
creates the SftpPoller object from the configuration hash argument passed
nconf | a hash with the following keys:
|
SFTPPOLLER-CONSTRUCTOR-ERROR | missing required key, invalid port or poll_interval given |
SFTPCLIENT-PARAMETER-ERROR | empty hostname passed |
SOCKET-CONNECT-ERROR | error establishing socket connection (no listener, port blocked, etc); timeout establishing socket connection |
SSH2CLIENT-CONNECT-ERROR | no user name set; ssh2 or libssh2 error |
SSH2-ERROR | error initializing or establishing ssh2 session |
SSH2CLIENT-AUTH-ERROR | no proper authentication method found |
SFTPCLIENT-CONNECT-ERROR | error initializing sftp session or getting remote path |
list<hash<SftpPollerFileEventInfo> > SftpPoller::SftpPoller::getFiles | ( | int | sort = SftpPoller::SortNone , |
int | order = SftpPoller::OrderAsc |
||
) |
returns a list of regular file hashes matching any file name mask set for the object
sort | the sort option for the list returned |
order | the ordering of sorted data returned |
name:
the name of the file, link, or directorysize:
the size of the file in bytesuid:
the UID of the owner of the filegid:
the GID of the owner of the filemode:
the permissions / mode of the fileatime:
the last accessed date/time of the filemtime:
the last modified date/time of the filetype:
the type of file is always "REGULAR"
perm:
a string giving UNIX-style permissions for the file (ex: "-rwxr-xr-x") int SftpPoller::SftpPoller::getStoreFile | ( | string | remote_path, |
string | local_path, | ||
*timeout | n_timeout | ||
) |
retrieves a remote file and stores it to a local path
remote_path | the remote file path |
local_path | the local file path |
n_timeout | a timeout in milliseconds |
|
pure virtual |
called after singleFileEvent() for each matching file individually whenever matching files are polled with the list of matching file names; if any error occurs here, the polling operation stops
This method would normally delete / rename / move files processed by singleFileEvent() so that they would not be polled a second time. If an error occurs in this operation, then the polling event will stop since continuing after failing to delete, rename, or move a file already processed would cause the file to be processed more than once.
fih | a hash of file data and information with the following keys:
|
|
pure virtual |
called for each matching file individually whenever matching files are polled with the list of matching file names; if any error occurs here, the error is logged and the polling operation is retried
fih | a hash of file data and information with the following keys:
|
int SftpPoller::SftpPoller::start | ( | ) |
starts polling in the background; returns the thread ID of the polling thread
if polling had already been started, then the thread ID of the polling thread is returned immediately
SftpPoller::SftpPoller::startInline | ( | ) |
starts the polling operation inline (not in a background thread)
SFTPPOLLER-ERROR | this exception is thrown if polling is already in progress |
SftpPoller::SftpPoller::stop | ( | ) |
stops the polling operation, returns when the polling operation has been stopped
if polling was not in progress then this method returns immediately
THREAD-ERROR | this exception is thrown if this method is called from the event thread since it would result in a deadlock |
SftpPoller::SftpPoller::stopNoWait | ( | ) |
stops the polling operation, returns immediately
SftpPoller::SftpPoller::waitStop | ( | ) |
waits indefinitely for the polling operation to stop; if polling was not in progress then this method returns immediately
THREAD-ERROR | this exception is thrown if this method is called from the event thread since it would result in a deadlock |