Qore FtpPoller Module Reference 2.1
Loading...
Searching...
No Matches
FtpPoller.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* FtpPoller.qm Copyright 2019 - 2024 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
121namespace FtpPoller {
123const AppName = "FTP";
124
126const EVENT_FTP_FILE = "ftp-file-event";
127
129
138
139public:
141 const OrderAsc = 0;
143 const OrderDesc = 1;
144
146 const SortNone = 0;
148 const SortName = 1;
149 const SortDate = 2;
150
152 const RequiredKeys = ...;
153
154
156 const RequiredKeysWithHost = RequiredKeys + "host";
157
159 const Defaults = ...;
160
161
163 const OptionalKeys = ...;
164
165
167 const AllKeys = RequiredKeysWithHost + keys Defaults + OptionalKeys;
168
170 const ErrorDelay = 1m;
171
172protected:
174 string protocol;
175
177 string host;
178
180 int port;
181
183 string user;
184
186 string url;
187
189 hash<UrlInfo> urlh;
190
192 *string pass;
193
195 softlist<string> path = ".";
196
199
201 *string mask;
202
205
207 string local_dir;
208
211
214
216
219
221
224
226 bool runflag = False;
227
230
232 bool fatal = False;
233
235 int pollcnt = 0;
236
238 Mutex m();
239
241 int tid;
242
244 timeout timeout;
245
247 Counter sc();
248
251
253 int reopts = 0;
254
256 *softint minage;
257
259 *code log_info;
260
263
266
269
271 *code sleep;
272
274 FtpClient new_ftp;
275
276public:
277
279
321 constructor(Qore::FtpClient n_ftp, hash<auto> nconf);
322
323
325
365 constructor(hash<auto> nconf);
366
367
370
371
373 updateOptions(FtpClient ftp);
374
375
378
379
380protected:
381 setup(FtpClient ftp);
382public:
383
384
386protected:
387 logInfo(string fmt, ...);
388public:
389
390
392protected:
393 logDetail(string fmt, ...);
394public:
395
396
398protected:
399 logDebug(string fmt, ...);
400public:
401
402
404protected:
406public:
407
408
410
413 getStoreFile(string remote_path, string local_path);
414
415
417 string getTextFile(string path);
418
419
421 binary getFile(string path);
422
423
425 rename(string old, string nnew);
426
427
429 removeFile(string fn);
430
431
433
443 list<hash<FtpPollerFileEventInfo>> getFiles(string subdir, int sort = FtpPoller::SortNone, int order = FtpPoller::OrderAsc);
444
445
447
450 int start();
451
452
454
457
458
460
468
469
471
477
478
480
484
485
487 bool runOnce();
488
489
491 hash<FtpPollerFileEventInfo> getRemoteFileData(hash<FtpPollerFileEventInfo> event);
492
493
495protected:
496 hash<FtpPollerFileEventInfo> retrieveTempFile(hash<FtpPollerFileEventInfo> event);
497public:
498
499
501protected:
502 hash<FtpPollerFileEventInfo> retrieveFile(hash<FtpPollerFileEventInfo> event);
503public:
504
505
507protected:
508 ftpSleep(softint secs);
509public:
510
511
513protected:
515public:
516
517
519
521 *bool fileEvent(list<hash<FtpPollerFileEventInfo>> l);
522
523
525
529 abstract singleFileEvent(hash<FtpPollerFileEventInfo> event);
530
532
541 abstract postSingleFileEvent(hash<FtpPollerFileEventInfo> event);
542
544
548 static checkPath(string path, string type, bool write = False);
549};
550
552
555
556public:
559
560
561protected:
563 EmbeddedFtpPoller poller;
564
565public:
566
568 constructor(*hash<auto> options);
569
570
571 destructor();
572
573
574 string getName();
575
576
578 *string getDesc();
579
580
582
585 updateConnectionObjects(object conn, object connobj);
586
587
589
593protected:
594 hash<string, hash<DataProviderMessageInfo>> getEventTypesImpl();
595public:
596
597};
598
600
605
606public:
608 const ProviderInfo = ...;
609
610
612 constructor(*hash<auto> options) ;
613
614
615protected:
616 hash<DataProviderInfo> getStaticInfoImpl();
617public:
618
619};
620
622
627
628public:
630 const ProviderInfo = ...;
631
632
634 constructor(*hash<auto> options) ;
635
636
638
641
642
644
647
648
649protected:
650 hash<DataProviderInfo> getStaticInfoImpl();
651public:
652
653};
654
656class FtpPollerDataProviderFactory : public AbstractDataProviderFactory {
657
658public:
659protected:
661 static Class cls = new Class("FtpDelayedPollerDataProvider");
662
664 const FactoryInfo = ...;
665
666
667public:
668
670
672protected:
673 hash<DataProviderFactoryInfo> getInfoImpl();
674public:
675
676
678
680protected:
681 hash<DataProviderInfo> getProviderInfoImpl();
682public:
683
684
686protected:
688public:
689
690};
691};
692
693// private namespace; not exported
694namespace Priv {
695class EmbeddedFtpPoller : public FtpPoller {
696
697public:
698protected:
700 Observable observable;
701
702public:
703
704 constructor(FtpPollerDataProviderBase provider, hash<auto> options) ;
705
706
707 singleFileEvent(hash<FtpPollerFileEventInfo> event);
708
709
710 postSingleFileEvent(hash<FtpPollerFileEventInfo> event);
711
712};
713
714const FtpWhiteLogo = ...;
715
716
717const FtpBlackLogo = ...;
718
719};
Event-based data provider for FTP polling events.
Definition FtpPoller.qm.dox.h:626
stopEvents()
Called to stop generating events.
const ProviderInfo
Provider info.
Definition FtpPoller.qm.dox.h:630
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:554
*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:558
updateConnectionObjects(object conn, object connobj)
Update any connection used by the data provider.
EmbeddedFtpPoller poller
The file poller itself.
Definition FtpPoller.qm.dox.h:563
The FTP poller data provider factory.
Definition FtpPoller.qm.dox.h:656
const FactoryInfo
Factory info.
Definition FtpPoller.qm.dox.h:664
Class getClassImpl()
Returns the class for the data provider object.
static Class cls
Data provider type info.
Definition FtpPoller.qm.dox.h:661
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:604
const ProviderInfo
Provider info.
Definition FtpPoller.qm.dox.h:608
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:207
logInfo(string fmt,...)
calls the "log_info" closure or call reference with important information
const SortNone
no sorting
Definition FtpPoller.qm.dox.h:146
hash< FtpPollerFileEventInfo > getRemoteFileData(hash< FtpPollerFileEventInfo > event)
Retrieves remote file data and adds it to the event data.
*string move_remote_file
Remote target directory for moving the file on the remote FTP server after processing.
Definition FtpPoller.qm.dox.h:223
int port
port
Definition FtpPoller.qm.dox.h:180
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:271
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:265
stopNoWait()
stops the polling operation, returns immediately
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:201
rename(string old, string nnew)
renames a file on the server
int tid
polling tid
Definition FtpPoller.qm.dox.h:241
*string pass
password
Definition FtpPoller.qm.dox.h:192
*code start_thread
optional start thread closure
Definition FtpPoller.qm.dox.h:268
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
bool delete_remote_file
Delete file on remote FTP server after processing?
Definition FtpPoller.qm.dox.h:218
string host
host or address name
Definition FtpPoller.qm.dox.h:177
*code log_detail
optional detail log closure
Definition FtpPoller.qm.dox.h:262
*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:213
logDetail(string fmt,...)
calls the "log_detail" closure or call reference with detail information
abstract postSingleFileEvent(hash< FtpPollerFileEventInfo > event)
called after singleFileEvent() for each matching file individually
string url
url
Definition FtpPoller.qm.dox.h:186
*code log_info
optional info log closure
Definition FtpPoller.qm.dox.h:259
*softint minage
minimum file age
Definition FtpPoller.qm.dox.h:256
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:210
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
updateOptions(FtpClient ftp)
Updates options.
run()
starts the polling operation
string getTextFile(string path)
retrieves a text file and returns the file's contents
int poll_interval
poll interval in seconds
Definition FtpPoller.qm.dox.h:204
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:229
timeout timeout
timeout in ms
Definition FtpPoller.qm.dox.h:244
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
FtpClient new_ftp
Connection to update while polling.
Definition FtpPoller.qm.dox.h:274
Qore::FtpClient ftp
FtpClient object.
Definition FtpPoller.qm.dox.h:250
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:141
string user
user
Definition FtpPoller.qm.dox.h:183
logDebug(string fmt,...)
calls the "log_debug" closure or call reference with verbose debugging information
hash< UrlInfo > urlh
url hash
Definition FtpPoller.qm.dox.h:189
string protocol
Protocol ("ftp" or "ftps")
Definition FtpPoller.qm.dox.h:174
startInline()
starts the polling operation inline (not in a background thread)
string rootFtpPath
path after connecting to Ftp server
Definition FtpPoller.qm.dox.h:198
main FtpPoller namespace
const EVENT_FTP_FILE
FTP file event constant.
Definition FtpPoller.qm.dox.h:126
const AppName
Generic FTP server app name.
Definition FtpPoller.qm.dox.h:123