Qore SftpPoller Module Reference 1.4.1
SftpPoller.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* SftpPoller.qm Copyright (C) 2014 - 2022 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23*/
24
25// make sure we have the required qore version
26
27// assume local vars and do not allow $ chars
28
29
30
99namespace SftpPoller {
102
103public:
105 const OrderAsc = 0;
107 const OrderDesc = 1;
108
110 const SortNone = 0;
112 const SortName = 1;
113 //const SortDate = 2;
114
116 const RequiredKeys = ...;
117
118
120 const RequiredKeysWithHost = RequiredKeys + "host";
121
123 const Defaults = ...;
124
125
127 const OptionalKeys = ...;
128
129
131 const AllKeys = RequiredKeysWithHost + Defaults.keys() + OptionalKeys;
132
134 const ErrorDelay = 1m;
135
136protected:
138 string host;
139
141 int port;
142
144 string user;
145
147 string url;
148
150 *string pass;
151
153 *string keyfile;
154
156 softlist<string> path = ".";
157
160
162 *string mask;
163
166
168 bool runflag = False;
169
172
174 bool fatal = False;
175
177 int pollcnt = 0;
178
180 Mutex m();
181
183 int tid;
184
186 timeout timeout;
187
189 Counter sc();
190
193
195 int reopts = 0;
196
198 *softint minage;
199
201 *string encoding;
202
204 *code log_info;
205
208
211
214
216 *code sleep;
217
219 bool binary;
220
223
226
229
230public:
231
233
260 constructor(Qore::SSH2::SFTPClient n_sftp, hash<auto> nconf);
261
262
264
295 constructor(hash<auto> nconf);
296
297
300
301
304
305
307protected:
308 logInfo(string fmt);
309public:
310
311
313protected:
314 logDetail(string fmt);
315public:
316
317
319protected:
320 logDebug(string fmt);
321public:
322
323
325protected:
327public:
328
329
331
337 int getStoreFile(string remote_path, string local_path, *timeout n_timeout);
338
339
341 string getTextFile(string path, *timeout n_timeout, *string n_encoding);
342
343
345 binary getFile(string path, *timeout n_timeout);
346
347
349 rename(string old, string nnew, *timeout n_timeout);
350
351
353 removeFile(string fn, *timeout n_timeout);
354
355
357 *hash<Qore::SSH2::Ssh2StatInfo> stat(string path, *timeout n_timeout);
358
359
361
364 checkRemotePath(string path, bool write = False, *timeout n_timeout);
365
366
368
382 list<hash<SftpPollerFileEventInfo>> getFiles(int sort = SftpPoller::SortNone, int order = SftpPoller::OrderAsc);
383
384
386
389 int start();
390
391
393
396
397
399
406
407
409
413
414
416
420
421
423 bool runOnce();
424
425
427protected:
428 sftpSleep(softint secs);
429public:
430
431
433protected:
435public:
436
437
439 *bool fileEvent(list<hash<SftpPollerFileEventInfo>> l);
440
441
443
456 abstract singleFileEvent(hash<SftpPollerFileEventInfo> fih);
457
459
476 abstract postSingleFileEvent(hash<SftpPollerFileEventInfo> fih);
477
479
482 static checkPath(string path, string type, bool write = False);
483};
484};
bool runOnce()
runs a single poll (useful for checking for errors inline before starting a background thread)
int port
port
Definition: SftpPoller.qm.dox.h:141
Counter sc()
stop counter
abstract postSingleFileEvent(hash< SftpPollerFileEventInfo > fih)
called after singleFileEvent() for each matching file individually whenever matching files are polled...
abstract singleFileEvent(hash< SftpPollerFileEventInfo > fih)
called for each matching file individually whenever matching files are polled with the list of matchi...
int poll_interval
poll interval in seconds
Definition: SftpPoller.qm.dox.h:165
string host
host or address name
Definition: SftpPoller.qm.dox.h:138
*string pass
password; one of "pass" or "keyfile" *must* be set
Definition: SftpPoller.qm.dox.h:150
static checkPath(string path, string type, bool write=False)
checks a path on the local file system
constructor(hash< auto > nconf)
creates the SftpPoller object from the configuration hash argument passed
stop()
stops the polling operation, returns when the polling operation has been stopped
sftpSleep(softint secs)
sleeps for the specificed number of seconds
Mutex m()
start mutex
*code sleep
optional sleep closure
Definition: SftpPoller.qm.dox.h:216
bool binary
binary transfer flag (for singleFileEvent())
Definition: SftpPoller.qm.dox.h:219
string rootSftpPath
path after connect to SFTP server
Definition: SftpPoller.qm.dox.h:159
rename(string old, string nnew, *timeout n_timeout)
renames a file on the server
binary getFile(string path, *timeout n_timeout)
retrieves a binary file and returns the file's contents
string url
url
Definition: SftpPoller.qm.dox.h:147
Qore::SSH2::SFTPClient sftp
SFTPClient object.
Definition: SftpPoller.qm.dox.h:192
stopNoWait()
stops the polling operation, returns immediately
waitStop()
waits indefinitely for the polling operation to stop; if polling was not in progress then this method...
*code log_debug
optional debug log closure
Definition: SftpPoller.qm.dox.h:210
run()
starts the polling operation
bool writable
chech if path is writable for others in constructor
Definition: SftpPoller.qm.dox.h:222
int start()
starts polling in the background; returns the thread ID of the polling thread
int getStoreFile(string remote_path, string local_path, *timeout n_timeout)
retrieves a remote file and stores it to a local path
*code log_detail
optional detail log closure
Definition: SftpPoller.qm.dox.h:207
string check_file
name of check writable file
Definition: SftpPoller.qm.dox.h:225
logDebug(string fmt)
calls the "log_debug" closure or call reference with verbose debugging information
int tid
polling tid
Definition: SftpPoller.qm.dox.h:183
setMask()
converts a glob mask into a regex
*string keyfile
path to the ssh private key in PEM format; one of "pass" or "keyfile" *must* be set
Definition: SftpPoller.qm.dox.h:153
timeout timeout
timeout in ms
Definition: SftpPoller.qm.dox.h:186
*softint minage
minimum file age
Definition: SftpPoller.qm.dox.h:198
string user
user
Definition: SftpPoller.qm.dox.h:144
constructor(Qore::SSH2::SFTPClient n_sftp, hash< auto > nconf)
creates the SftpPoller object from the SFTPClient argument and configuration hash argument passed
*code log_info
optional info log closure
Definition: SftpPoller.qm.dox.h:204
*bool skip_file_content_retrieval
whether or not to skip the file content retrieval in runOnce()
Definition: SftpPoller.qm.dox.h:228
string getTextFile(string path, *timeout n_timeout, *string n_encoding)
retrieves a text file and returns the file's contents
bool get_files
internal "get files" flag
Definition: SftpPoller.qm.dox.h:171
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
*string encoding
file encoding for text files
Definition: SftpPoller.qm.dox.h:201
*bool fileEvent(list< hash< SftpPollerFileEventInfo > > l)
called for each poll with a list of all files matched before transfer; if this method returns False o...
startInline()
starts the polling operation inline (not in a background thread)
logInfo(string fmt)
calls the "log_info" closure or call reference with important information
*code start_thread
optional start thread closure
Definition: SftpPoller.qm.dox.h:213
removeFile(string fn, *timeout n_timeout)
deletes a file on the server
*string mask
file glob name mask (ignored if "regex_mask" also set)
Definition: SftpPoller.qm.dox.h:162
logDetail(string fmt)
calls the "log_detail" closure or call reference with detail information
checkRemotePath(string path, bool write=False, *timeout n_timeout)
check if a remote path is writable
destructor()
stops the polling operation if in progress and destroys the object
int getPollCount()
returns the current poll count
*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 ...
main SftpPoller namespace