Qore FtpPoller Module Reference 2.0
Loading...
Searching...
No Matches
FtpPoller.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* FtpPoller.qm Copyright 2019 - 2023 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
26// make sure we have the required qore version
27
28
29
117namespace FtpPoller {
119const EVENT_FTP_FILE = "ftp-file-event";
120
123
124public:
126 const OrderAsc = 0;
128 const OrderDesc = 1;
129
131 const SortNone = 0;
133 const SortName = 1;
134 const SortDate = 2;
135
137 const RequiredKeys = ...;
138
139
141 const RequiredKeysWithHost = RequiredKeys + "host";
142
144 const Defaults = {
145 "protocol": "ftp",
146 "port": 21,
147 "mask": "*",
148 "poll_interval": 10,
149 "reopts": 0,
150 "tempfile_template": ".tmp.%s.part",
151 "atomic_transfer": False,
152 };
153
155 const OptionalKeys = ...;
156
157
159 const AllKeys = RequiredKeysWithHost + keys Defaults + OptionalKeys;
160
162 const ErrorDelay = 1m;
163
164protected:
166 string protocol;
167
169 string host;
170
172 int port;
173
175 string user;
176
178 string url;
179
181 hash<UrlInfo> urlh;
182
184 *string pass;
185
187 softlist<string> path = ".";
188
191
193 *string mask;
194
197
199 string local_dir;
200
203
206
208 bool runflag = False;
209
212
214 bool fatal = False;
215
217 int pollcnt = 0;
218
220 Mutex m();
221
223 int tid;
224
226 timeout timeout;
227
229 Counter sc();
230
233
235 int reopts = 0;
236
238 *softint minage;
239
241 *code log_info;
242
245
248
251
253 *code sleep;
254
255public:
256
258
295 constructor(Qore::FtpClient n_ftp, hash<auto> nconf);
296
297
299
338 constructor(hash<auto> nconf);
339
340
343
344
347
348
350protected:
351 logInfo(string fmt);
352public:
353
354
356protected:
357 logDetail(string fmt);
358public:
359
360
362protected:
363 logDebug(string fmt);
364public:
365
366
368protected:
370public:
371
372
374
377 getStoreFile(string remote_path, string local_path);
378
379
381 string getTextFile(string path);
382
383
385 binary getFile(string path);
386
387
389 rename(string old, string nnew);
390
391
393 removeFile(string fn);
394
395
397
407 list<hash<FtpPollerFileEventInfo>> getFiles(string subdir, int sort = FtpPoller::SortNone, int order = FtpPoller::OrderAsc);
408
409
411
414 int start();
415
416
418
421
422
424
432
433
435
441
442
444
448
449
451 bool runOnce();
452
453
455 hash<FtpPollerFileEventInfo> getRemoteFileData(hash<FtpPollerFileEventInfo> event);
456
457
459protected:
460 hash<FtpPollerFileEventInfo> retrieveTempFile(hash<FtpPollerFileEventInfo> event);
461public:
462
463
465protected:
466 hash<FtpPollerFileEventInfo> retrieveFile(hash<FtpPollerFileEventInfo> event);
467public:
468
469
471protected:
472 ftpSleep(softint secs);
473public:
474
475
477protected:
479public:
480
481
483
485 *bool fileEvent(list<hash<FtpPollerFileEventInfo>> l);
486
487
489
493 abstract singleFileEvent(hash<FtpPollerFileEventInfo> event);
494
496
505 abstract postSingleFileEvent(hash<FtpPollerFileEventInfo> event);
506
508
512 static checkPath(string path, string type, bool write = False);
513};
514
516
519
520public:
523 "atomic_transfer": <DataProviderOptionInfo>{
524 "type": AbstractDataProviderType::get(BoolType),
525 "desc": "Use an atomic transfer mechanism with `local_dir` where remote files are first moved to a "
526 "temporary location and then moved to the final location when they have been fully transferred",
527 "default_value": True,
528 },
529
530 "local_dir": <DataProviderOptionInfo>{
531 "type": AbstractDataProviderType::get(StringOrNothingType),
532 "desc": "A local directory that will be used to retrieve files",
533 },
534
535 "mask": <DataProviderOptionInfo>{
536 "type": AbstractDataProviderType::get(StringType),
537 "desc": "The glob mask to use; will be treated as a regex if `regex` is `true`",
538 "default_value": "*",
539 },
540
541 "minage": <DataProviderOptionInfo>{
542 "type": AbstractDataProviderType::get(IntType),
543 "desc": "An integer giving the minimum file age in seconds before the file will be polled; this is "
544 "meant to work around non-atomic file transfer operations",
545 },
546
547 "poll_interval": <DataProviderOptionInfo>{
548 "type": AbstractDataProviderType::get(IntType),
549 "desc": "The interval in seconds between polling for files",
550 "default_value": 10,
551 },
552
553 "regex": <DataProviderOptionInfo>{
554 "type": AbstractDataProviderType::get(BoolType),
555 "desc": "If `true` then `mask` is treated as a regular expression instead of a glob pattern",
556 },
557
558 "reopt": <DataProviderOptionInfo>{
559 "type": AbstractDataProviderType::get(IntType),
560 "desc": "A bitfield of regular expression options (`1` = ignore case, `2` = treat EOL as a regular "
561 "character); ignored if `regex` is not `true`",
562 },
563
564 "sort_desc": <DataProviderOptionInfo>{
565 "type": AbstractDataProviderType::get(BoolType),
566 "desc": "Sort descending; if not given then an ascending sort is assumed if a `sort_type` is given",
567 },
568
569 "sort_type": <DataProviderOptionInfo>{
570 "type": AbstractDataProviderType::get(StringType),
571 "desc": "Either `name` or `date` for the data to use for sorting",
572 },
573
574 "url": <DataProviderOptionInfo>{
575 "type": AbstractDataProviderType::get(StringType),
576 "desc": "A URL for an FTP connection",
577 "required": True,
578 },
579 };
580
581protected:
583 EmbeddedFtpPoller poller;
584
585public:
586
588 constructor(*hash<auto> options);
589
590
591 destructor();
592
593
594 string getName();
595
596
598 *string getDesc();
599
600
602
606protected:
607 hash<string, hash<DataProviderMessageInfo>> getEventTypesImpl();
608public:
609
610};
611
613
618
619public:
621 const ProviderInfo = <DataProviderInfo>{
622 "type": "FtpPollerDataProvider",
623 "supports_observable": True,
624 "constructor_options": ConstructorOptions,
625 };
626
628 constructor(*hash<auto> options) ;
629
630
631protected:
632 hash<DataProviderInfo> getStaticInfoImpl();
633public:
634
635};
636
638
643
644public:
646 const ProviderInfo = <DataProviderInfo>{
647 "type": "FtpDelayedPollerDataProvider",
648 "supports_observable": True,
649 "constructor_options": ConstructorOptions,
650 };
651
653 constructor(*hash<auto> options) ;
654
655
657
660
661
662protected:
663 hash<DataProviderInfo> getStaticInfoImpl();
664public:
665
666};
667
669class FtpPollerDataProviderFactory : public AbstractDataProviderFactory {
670
671public:
672protected:
674 static Class cls = new Class("FtpPollerDataProvider");
675
677 const FactoryInfo = <DataProviderFactoryInfo>{
678 "name": "ftppoller",
679 "desc": "FTP poller data provider factory",
680 "children_can_support_observers": True,
681 };
682
683public:
684
686
688protected:
689 hash<DataProviderFactoryInfo> getInfoImpl();
690public:
691
692
694
696protected:
697 hash<DataProviderInfo> getProviderInfoImpl();
698public:
699
700
702protected:
704public:
705
706};
707};
708
709// private namespace; not exported
710namespace Priv {
711class EmbeddedFtpPoller : public FtpPoller {
712
713public:
714protected:
716 Observable observable;
717
718public:
719
720 constructor(FtpPollerDataProviderBase provider, hash<auto> options) ;
721
722
723 singleFileEvent(hash<FtpPollerFileEventInfo> event);
724
725
726 postSingleFileEvent(hash<FtpPollerFileEventInfo> event);
727
728};
729};
Event-based data provider for FTP polling events.
Definition: FtpPoller.qm.dox.h:642
const ProviderInfo
Provider info.
Definition: FtpPoller.qm.dox.h:646
constructor(*hash< auto > options)
Creates the object from constructor options.
observersReady()
Called when all observers have been added to the object.
Event-based data provider for FTP polling events.
Definition: FtpPoller.qm.dox.h:518
*string getDesc()
Returns the data provider description.
hash< string, hash< DataProviderMessageInfo > > getEventTypesImpl()
Returns a hash of all supported event types.
constructor(*hash< auto > options)
Creates the object from constructor options.
const ConstructorOptions
Constructor options.
Definition: FtpPoller.qm.dox.h:522
EmbeddedFtpPoller poller
The file poller itself.
Definition: FtpPoller.qm.dox.h:583
The FTP poller data provider factory.
Definition: FtpPoller.qm.dox.h:669
const FactoryInfo
Factory info.
Definition: FtpPoller.qm.dox.h:677
Class getClassImpl()
Returns the class for the data provider object.
static Class cls
Data provider type info.
Definition: FtpPoller.qm.dox.h:674
hash< DataProviderFactoryInfo > getInfoImpl()
Returns static factory information without provider_info.
hash< DataProviderInfo > getProviderInfoImpl()
Returns static provider information.
Event-based data provider for FTP polling events.
Definition: FtpPoller.qm.dox.h:617
const ProviderInfo
Provider info.
Definition: FtpPoller.qm.dox.h:621
constructor(*hash< auto > options)
Creates the object from constructor options.
static checkPath(string path, string type, bool write=False)
checks a path on the local file system
string local_dir
Local directory to transfer file.
Definition: FtpPoller.qm.dox.h:199
const SortNone
no sorting
Definition: FtpPoller.qm.dox.h:131
logInfo(string fmt)
calls the "log_info" closure or call reference with important information
hash< FtpPollerFileEventInfo > getRemoteFileData(hash< FtpPollerFileEventInfo > event)
Retrieves remote file data and adds it to the event data.
int port
port
Definition: FtpPoller.qm.dox.h:172
getStoreFile(string remote_path, string local_path)
retrieves a remote file and stores it to a local path
*code sleep
optional sleep closure
Definition: FtpPoller.qm.dox.h:253
list< hash< FtpPollerFileEventInfo > > getFiles(string subdir, int sort=FtpPoller::SortNone, int order=FtpPoller::OrderAsc)
returns a list of regular file hashes matching any file name mask set for the object
int start()
starts polling in the background; returns the thread ID of the polling thread
*code log_debug
optional debug log closure
Definition: FtpPoller.qm.dox.h:247
stopNoWait()
stops the polling operation, returns immediately
logDetail(string fmt)
calls the "log_detail" closure or call reference with detail information
destructor()
stops the polling operation if in progress and destroys the object
*string mask
file glob name mask (ignored if "regex_mask" also set)
Definition: FtpPoller.qm.dox.h:193
rename(string old, string nnew)
renames a file on the server
int tid
polling tid
Definition: FtpPoller.qm.dox.h:223
*string pass
password
Definition: FtpPoller.qm.dox.h:184
*code start_thread
optional start thread closure
Definition: FtpPoller.qm.dox.h:250
hash< FtpPollerFileEventInfo > retrieveTempFile(hash< FtpPollerFileEventInfo > event)
Retrieves the remote file to local_dir using a temporary file.
constructor(hash< auto > nconf)
creates the FtpPoller object from the configuration hash argument passed
binary getFile(string path)
retrieves a binary file and returns the file's contents
string host
host or address name
Definition: FtpPoller.qm.dox.h:169
*code log_detail
optional detail log closure
Definition: FtpPoller.qm.dox.h:244
*bool fileEvent(list< hash< FtpPollerFileEventInfo > > l)
called for each poll with a list of all files matched before transfer
Counter sc()
stop counter
bool atomic_transfer
Atomic transfer flag for use with local_dir.
Definition: FtpPoller.qm.dox.h:205
abstract postSingleFileEvent(hash< FtpPollerFileEventInfo > event)
called after singleFileEvent() for each matching file individually
string url
url
Definition: FtpPoller.qm.dox.h:178
*code log_info
optional info log closure
Definition: FtpPoller.qm.dox.h:241
*softint minage
minimum file age
Definition: FtpPoller.qm.dox.h:238
hash< FtpPollerFileEventInfo > retrieveFile(hash< FtpPollerFileEventInfo > event)
Retrieves the remote file to local_dir directly.
string tempfile_template
The temporary filename template when local_dir is set.
Definition: FtpPoller.qm.dox.h:202
stop()
stops the polling operation, returns when the polling operation has been stopped
bool runOnce()
runs a single poll (useful for checking for errors inline before starting a background thread)
ftpSleep(softint secs)
sleeps for the specificed number of seconds
Mutex m()
start mutex
run()
starts the polling operation
string getTextFile(string path)
retrieves a text file and returns the file's contents
logDebug(string fmt)
calls the "log_debug" closure or call reference with verbose debugging information
int poll_interval
poll interval in seconds
Definition: FtpPoller.qm.dox.h:196
constructor(Qore::FtpClient n_ftp, hash< auto > nconf)
creates the FtpPoller object from the FtpClient argument and configuration hash argument passed
bool get_files
internal "get files" flag
Definition: FtpPoller.qm.dox.h:211
timeout timeout
timeout in ms
Definition: FtpPoller.qm.dox.h:226
waitStop()
waits indefinitely for the polling operation to stop
int getPollCount()
returns the current poll count
removeFile(string fn)
deletes a file on the server
setMask()
converts a glob mask into a regex
Qore::FtpClient ftp
FtpClient object.
Definition: FtpPoller.qm.dox.h:232
abstract singleFileEvent(hash< FtpPollerFileEventInfo > event)
called for each matching file individually whenever matching files are polled
const OrderAsc
ascending sort order
Definition: FtpPoller.qm.dox.h:126
string user
user
Definition: FtpPoller.qm.dox.h:175
hash< UrlInfo > urlh
url hash
Definition: FtpPoller.qm.dox.h:181
string protocol
Protocol ("ftp" or "ftps")
Definition: FtpPoller.qm.dox.h:166
startInline()
starts the polling operation inline (not in a background thread)
string rootFtpPath
path after connecting to Ftp server
Definition: FtpPoller.qm.dox.h:190
main FtpPoller namespace
const EVENT_FTP_FILE
FTP file event constant.
Definition: FtpPoller.qm.dox.h:119