Qore SftpPoller Module Reference  1.0
SftpPoller.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
3 
4 /* SftpPoller.qm Copyright (C) 2014 - 2016 David Nichols
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 // requires ssh2 functionality
28 
29 // assume local vars and do not allow $ chars
30 
31 
32 /* Version History
33  * 2014-03-01 v1.0: David Nichols <david@qore.org>: initial version
34 */
35 
99 namespace SftpPoller {
102  class SftpPoller {
103 
104 public:
105  public :
107  const OrderAsc = 0;
109  const OrderDesc = 1;
110 
112  const SortNone = 0;
114  const SortName = 1;
115  //const SortDate = 2;
116 
118  const RequiredKeys = (
119  "sleep",
120  "start_thread",
121  );
122 
124  const RequiredKeysWithHost = RequiredKeys + "host";
125 
127  const Defaults = (
128  "port": 22,
129  "mask": "*",
130  "poll_interval": 10,
131  "reopts": 0,
132  "timeout": 30s,
133  "binary": False,
134  "writable": False,
135  "check_file": "qore-sftp-check-file",
136  );
137 
139  const OptionalKeys = (
140  "path", "user", "pass", "keyfile", "regex_mask", "minage",
141  "encoding", "log_info", "log_detail", "log_debug", "binary",
142  "sleep",
143  "start_thread",
144  );
145 
147  const AllKeys = RequiredKeysWithHost + Defaults.keys() + OptionalKeys;
148 
150  const ErrorDelay = 1m;
151 
152 public:
153 
154  private :
156  string host;
157 
159  int port;
160 
162  string user;
163 
165  string url;
166 
168  *string pass;
169 
171  *string keyfile;
172 
174  softlist path = ".";
175 
177  string rootSftpPath;
178 
180  *string mask;
181 
184 
186  bool runflag = False;
187 
189  bool get_files;
190 
192  bool fatal = False;
193 
195  int pollcnt = 0;
196 
198  Mutex m();
199 
201  int tid;
202 
204  timeout timeout;
205 
207  Counter sc();
208 
210  Qore::SSH2::SFTPClient sftp;
211 
213  int reopts = 0;
214 
216  *softint minage;
217 
219  *string encoding;
220 
222  *code log_info;
223 
225  *code log_detail;
226 
228  *code log_debug;
229 
232 
234  *code sleep;
235 
237  bool binary;
238 
240  bool writable;
241 
243  string check_file;
244 
245 public:
246 
248 
275  constructor(Qore::SSH2::SFTPClient n_sftp, hash nconf);
276 
277 
279 
309  constructor(hash nconf);
310 
311 
313  destructor();
314 
315 
317  int getPollCount();
318 
319 
321  private logInfo(string fmt);
322 
323 
325  private logDetail(string fmt);
326 
327 
329  private logDebug(string fmt);
330 
331 
333  private setMask();
334 
335 
337 
343  int getStoreFile(string remote_path, string local_path, *timeout n_timeout);
344 
345 
347  string getTextFile(string path, *timeout n_timeout, *string n_encoding);
348 
349 
351  binary getFile(string path, *timeout n_timeout);
352 
353 
355  rename(string old, string nnew, *timeout n_timeout);
356 
357 
359  removeFile(string fn, *timeout n_timeout);
360 
361 
363  *hash stat(string path, *timeout n_timeout);
364 
365 
367 
370  checkRemotePath(string path, bool write = False, *timeout n_timeout);
371 
372 
374 
388  list getFiles(int sort = SftpPoller::SortNone, int order = SftpPoller::OrderAsc);
389 
390 
392 
395  int start();
396 
397 
399 
401  stopNoWait();
402 
403 
405 
411  stop();
412 
413 
415 
418  waitStop();
419 
420 
422 
425  startInline();
426 
427 
429  bool runOnce();
430 
431 
433  private sftpSleep(softint secs);
434 
435 
437  private run();
438 
439 
441  *bool fileEvent(list l);
442 
443 
445 
458  abstract singleFileEvent(hash fih);
459 
461 
478  abstract postSingleFileEvent(hash fih);
479 
481 
484  static checkPath(string path, string type, bool write = False);
485  };
486 };
*string pass
password; one of "pass" or "keyfile" *must* be set
Definition: SftpPoller.qm.dox.h:168
int port
port
Definition: SftpPoller.qm.dox.h:159
string rootSftpPath
path after connect to SFTP server
Definition: SftpPoller.qm.dox.h:177
*code log_info
optional info log closure
Definition: SftpPoller.qm.dox.h:222
*code log_detail
optional detail log closure
Definition: SftpPoller.qm.dox.h:225
main SftpPoller namespace
Definition: SftpPoller.qm.dox.h:100
*code sleep
optional sleep closure
Definition: SftpPoller.qm.dox.h:234
string host
host or address name
Definition: SftpPoller.qm.dox.h:156
*softint minage
minimum file age
Definition: SftpPoller.qm.dox.h:216
*string encoding
file encoding for text files
Definition: SftpPoller.qm.dox.h:219
Qore::SSH2::SFTPClient sftp
SFTPClient object.
Definition: SftpPoller.qm.dox.h:210
string check_file
name of check writable file
Definition: SftpPoller.qm.dox.h:243
string url
url
Definition: SftpPoller.qm.dox.h:165
*string keyfile
path to the ssh private key in PEM format; one of "pass" or "keyfile" *must* be set ...
Definition: SftpPoller.qm.dox.h:171
string user
user
Definition: SftpPoller.qm.dox.h:162
bool get_files
internal "get files" flag
Definition: SftpPoller.qm.dox.h:189
*code start_thread
optional start thread closure
Definition: SftpPoller.qm.dox.h:231
*string mask
file glob name mask (ignored if "regex_mask" also set)
Definition: SftpPoller.qm.dox.h:180
int tid
polling tid
Definition: SftpPoller.qm.dox.h:201
bool writable
chech if path is writable for others in constructor
Definition: SftpPoller.qm.dox.h:240
*code log_debug
optional debug log closure
Definition: SftpPoller.qm.dox.h:228
int poll_interval
poll interval in seconds
Definition: SftpPoller.qm.dox.h:183
bool binary
binary transfer flag (for singleFileEvent())
Definition: SftpPoller.qm.dox.h:237
timeout timeout
timeout in ms
Definition: SftpPoller.qm.dox.h:204