Qore SftpPoller Module Reference  1.3
SftpPoller.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* SftpPoller.qm Copyright (C) 2014 - 2020 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 }
31 
98 namespace SftpPoller {
101 class SftpPoller {
102 
103 public:
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  "sleep",
118  "start_thread",
119  );
120 
122  const RequiredKeysWithHost = RequiredKeys + "host";
123 
125  const Defaults = {
126  "port": 22,
127  "mask": "*",
128  "poll_interval": 10,
129  "reopts": 0,
130  "timeout": 30s,
131  "binary": False,
132  "writable": False,
133  "check_file": "qore-sftp-check-file",
134  };
135 
137  const OptionalKeys = (
138  "path", "user", "pass", "keyfile", "regex_mask", "minage",
139  "encoding", "log_info", "log_detail", "log_debug", "binary",
140  "sleep",
141  "start_thread",
142  "skip_file_content_retrieval",
143  );
144 
146  const AllKeys = RequiredKeysWithHost + Defaults.keys() + OptionalKeys;
147 
149  const ErrorDelay = 1m;
150 
151 protected:
153  string host;
154 
156  int port;
157 
159  string user;
160 
162  string url;
163 
165  *string pass;
166 
168  *string keyfile;
169 
171  softlist<string> path = ".";
172 
174  string rootSftpPath;
175 
177  *string mask;
178 
181 
183  bool runflag = False;
184 
186  bool get_files;
187 
189  bool fatal = False;
190 
192  int pollcnt = 0;
193 
195  Mutex m();
196 
198  int tid;
199 
201  timeout timeout;
202 
204  Counter sc();
205 
208 
210  int reopts = 0;
211 
213  *softint minage;
214 
216  *string encoding;
217 
219  *code log_info;
220 
222  *code log_detail;
223 
225  *code log_debug;
226 
229 
231  *code sleep;
232 
234  bool binary;
235 
237  bool writable;
238 
240  string check_file;
241 
244 
245 public:
246 
248 
275  constructor(Qore::SSH2::SFTPClient n_sftp, hash<auto> nconf);
276 
277 
279 
310  constructor(hash<auto> nconf);
311 
312 
314  destructor();
315 
316 
318  int getPollCount();
319 
320 
322 protected:
323  logInfo(string fmt);
324 public:
325 
326 
328 protected:
329  logDetail(string fmt);
330 public:
331 
332 
334 protected:
335  logDebug(string fmt);
336 public:
337 
338 
340 protected:
341  setMask();
342 public:
343 
344 
346 
352  int getStoreFile(string remote_path, string local_path, *timeout n_timeout);
353 
354 
356  string getTextFile(string path, *timeout n_timeout, *string n_encoding);
357 
358 
360  binary getFile(string path, *timeout n_timeout);
361 
362 
364  rename(string old, string nnew, *timeout n_timeout);
365 
366 
368  removeFile(string fn, *timeout n_timeout);
369 
370 
372  *hash<Qore::SSH2::Ssh2StatInfo> stat(string path, *timeout n_timeout);
373 
374 
376 
379  checkRemotePath(string path, bool write = False, *timeout n_timeout);
380 
381 
383 
397  list<hash<SftpPollerFileEventInfo>> getFiles(int sort = SftpPoller::SortNone, int order = SftpPoller::OrderAsc);
398 
399 
401 
404  int start();
405 
406 
408 
410  stopNoWait();
411 
412 
414 
420  stop();
421 
422 
424 
427  waitStop();
428 
429 
431 
434  startInline();
435 
436 
438  bool runOnce();
439 
440 
442 protected:
443  sftpSleep(softint secs);
444 public:
445 
446 
448 protected:
449  run();
450 public:
451 
452 
454  *bool fileEvent(list<hash<SftpPollerFileEventInfo>> l);
455 
456 
458 
471  abstract singleFileEvent(hash<SftpPollerFileEventInfo> fih);
472 
474 
491  abstract postSingleFileEvent(hash<SftpPollerFileEventInfo> fih);
492 
494 
497  static checkPath(string path, string type, bool write = False);
498 };
499 };
SftpPoller::SftpPoller::log_info
*code log_info
optional info log closure
Definition: SftpPoller.qm.dox.h:219
SftpPoller::SftpPoller::poll_interval
int poll_interval
poll interval in seconds
Definition: SftpPoller.qm.dox.h:180
SftpPoller::SftpPoller::user
string user
user
Definition: SftpPoller.qm.dox.h:159
SftpPoller::SftpPoller::minage
*softint minage
minimum file age
Definition: SftpPoller.qm.dox.h:213
SftpPoller::SftpPoller::pass
*string pass
password; one of "pass" or "keyfile" *must* be set
Definition: SftpPoller.qm.dox.h:165
SftpPoller::SftpPoller::host
string host
host or address name
Definition: SftpPoller.qm.dox.h:153
SftpPoller::SftpPoller::keyfile
*string keyfile
path to the ssh private key in PEM format; one of "pass" or "keyfile" *must* be set
Definition: SftpPoller.qm.dox.h:168
SftpPoller::SftpPoller::sleep
*code sleep
optional sleep closure
Definition: SftpPoller.qm.dox.h:231
SftpPoller::SftpPoller::url
string url
url
Definition: SftpPoller.qm.dox.h:162
SftpPoller::SftpPoller::rootSftpPath
string rootSftpPath
path after connect to SFTP server
Definition: SftpPoller.qm.dox.h:174
Qore::SSH2::SFTPClient
SftpPoller::SftpPoller::start_thread
*code start_thread
optional start thread closure
Definition: SftpPoller.qm.dox.h:228
SftpPoller::SftpPoller::encoding
*string encoding
file encoding for text files
Definition: SftpPoller.qm.dox.h:216
SftpPoller::SftpPoller::mask
*string mask
file glob name mask (ignored if "regex_mask" also set)
Definition: SftpPoller.qm.dox.h:177
SftpPoller::SftpPoller::log_detail
*code log_detail
optional detail log closure
Definition: SftpPoller.qm.dox.h:222
SftpPoller::SftpPoller::skip_file_content_retrieval
*bool skip_file_content_retrieval
whether or not to skip the file content retrieval in runOnce()
Definition: SftpPoller.qm.dox.h:243
SftpPoller
main SftpPoller namespace
SftpPoller::SftpPoller::timeout
timeout timeout
timeout in ms
Definition: SftpPoller.qm.dox.h:201
SftpPoller::SftpPoller::writable
bool writable
chech if path is writable for others in constructor
Definition: SftpPoller.qm.dox.h:237
SftpPoller::SftpPoller::tid
int tid
polling tid
Definition: SftpPoller.qm.dox.h:198
SftpPoller::SftpPoller::check_file
string check_file
name of check writable file
Definition: SftpPoller.qm.dox.h:240
SftpPoller::SftpPoller::port
int port
port
Definition: SftpPoller.qm.dox.h:156
SftpPoller::SftpPoller::get_files
bool get_files
internal "get files" flag
Definition: SftpPoller.qm.dox.h:186
SftpPoller::SftpPoller::log_debug
*code log_debug
optional debug log closure
Definition: SftpPoller.qm.dox.h:225
SftpPoller::SftpPoller::binary
bool binary
binary transfer flag (for singleFileEvent())
Definition: SftpPoller.qm.dox.h:234
SftpPoller::SftpPoller::sftp
Qore::SSH2::SFTPClient sftp
SFTPClient object.
Definition: SftpPoller.qm.dox.h:207