Qore Programming Language  0.9.16
QoreFtpClient.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreFtpClient.h
4 
5  thread-safe Qore QoreFtpClient object
6 
7  Qore Programming Language
8 
9  Copyright (C) 2003 - 2019 Qore Technologies, s.r.o.
10 
11  Permission is hereby granted, free of charge, to any person obtaining a
12  copy of this software and associated documentation files (the "Software"),
13  to deal in the Software without restriction, including without limitation
14  the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  and/or sell copies of the Software, and to permit persons to whom the
16  Software is furnished to do so, subject to the following conditions:
17 
18  The above copyright notice and this permission notice shall be included in
19  all copies or substantial portions of the Software.
20 
21  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  DEALINGS IN THE SOFTWARE.
28 
29  Note that the Qore library is released under a choice of three open-source
30  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
31  information.
32 */
33 
34 #ifndef _QORE_QOREFTPCLIENT_H
35 
36 #define _QORE_QOREFTPCLIENT_H
37 
38 #include <qore/InputStream.h>
39 #include <qore/OutputStream.h>
40 
41 #define DEFAULT_FTP_CONTROL_PORT 21
42 #define DEFAULT_FTP_DATA_PORT 20
43 
44 #define DEFAULT_USERNAME "anonymous"
45 #define DEFAULT_PASSWORD "[email protected]"
46 
47 class FtpResp;
48 class Queue;
49 
51 
72 protected:
74  hashdecl qore_ftp_private *priv;
75 
77  DLLLOCAL QoreFtpClient(const QoreFtpClient&);
78 
80  DLLLOCAL QoreFtpClient& operator=(const QoreFtpClient&);
81 
82 public:
84 
89  DLLEXPORT QoreFtpClient(const QoreString *url, ExceptionSink *xsink);
90 
92  DLLEXPORT QoreFtpClient();
93 
95  DLLEXPORT ~QoreFtpClient();
96 
98 
102  DLLEXPORT int connect(ExceptionSink *xsink);
103 
105 
108  DLLEXPORT int disconnect();
109 
111 
117  DLLEXPORT int cwd(const char *dir, ExceptionSink *xsink);
118 
120 
124  DLLEXPORT QoreStringNode *pwd(ExceptionSink *xsink);
125 
127 
133  DLLEXPORT int put(const char *localpath, const char *remotename, ExceptionSink *xsink);
134 
136 
142  DLLEXPORT int put(InputStream *is, const char* remotename, ExceptionSink* xsink);
143 
145 
154  DLLEXPORT int get(const char *remotepath, const char *localname, ExceptionSink *xsink);
155 
157 
166  DLLEXPORT int get(const char *remotepath, OutputStream *os, ExceptionSink *xsink);
167 
169 
176  DLLEXPORT int putData(const void *data, qore_size_t len, const char *remotename, ExceptionSink *xsink);
177 
179 
184  DLLEXPORT QoreStringNode *getAsString(const char *remotepath, ExceptionSink *xsink);
185 
187 
192  DLLEXPORT BinaryNode *getAsBinary(const char *remotepath, ExceptionSink *xsink);
193 
195 
201  DLLEXPORT int rename(const char *from, const char *to, ExceptionSink *xsink);
202 
204 
210  DLLEXPORT QoreStringNode *list(const char *path, bool long_list, ExceptionSink *xsink);
211 
213 
218  DLLEXPORT int del(const char *file, ExceptionSink *xsink);
219 
221 
226  DLLEXPORT int mkdir(const char *remotepath, ExceptionSink *xsink);
227 
229 
234  DLLEXPORT int rmdir(const char *remotepath, ExceptionSink *xsink);
235 
237  DLLEXPORT int getPort() const;
238 
240  DLLEXPORT const char *getUserName() const;
241 
243  DLLEXPORT const char *getPassword() const;
244 
246  DLLEXPORT const char *getHostName() const;
247 
249 
254  DLLEXPORT void setURL(const QoreString *url, ExceptionSink *xsink);
255 
257 
260  DLLEXPORT QoreStringNode *getURL() const;
261 
263  DLLEXPORT void setPort(int p);
264 
266  DLLEXPORT void setUserName(const char *u);
267 
269  DLLEXPORT void setPassword(const char *p);
270 
272  DLLEXPORT void setHostName(const char *h);
273 
275 
277  DLLEXPORT int setSecure();
278 
280 
282  DLLEXPORT int setInsecure();
283 
285 
289  DLLEXPORT int setInsecureData();
290 
292 
295  DLLEXPORT bool isSecure() const;
296 
298 
301  DLLEXPORT bool isDataSecure() const;
302 
304 
307  DLLEXPORT const char *getSSLCipherName() const;
308 
310 
313  DLLEXPORT const char *getSSLCipherVersion() const;
314 
316  DLLEXPORT long verifyPeerCertificate() const;
317 
319  DLLEXPORT void setModeAuto();
320 
322  DLLEXPORT void setModeEPSV();
323 
325  DLLEXPORT void setModePASV();
326 
328  DLLEXPORT void setModePORT();
329 
331  DLLEXPORT const char* getMode() const;
332 
333  DLLEXPORT void clearWarningQueue(ExceptionSink* xsink);
334  DLLEXPORT void setWarningQueue(ExceptionSink* xsink, int64 warning_ms, int64 warning_bs, Queue* wq, QoreValue arg, int64 min_ms = 1000);
335  DLLEXPORT QoreHashNode* getUsageInfo() const;
336  DLLEXPORT void clearStats();
337 
339 
345  DLLEXPORT void setNetworkFamily(int family);
346 
348 
352  DLLEXPORT int getNetworkFamily() const;
353 
355 
370  DLLEXPORT QoreHashNode* getControlPeerInfo(ExceptionSink* xsink, bool host_lookup) const;
371 
373 
388  DLLEXPORT QoreHashNode* getDataPeerInfo(ExceptionSink* xsink, bool host_lookup) const;
389 
391 
406  DLLEXPORT QoreHashNode* getControlSocketInfo(ExceptionSink* xsink, bool host_lookup) const;
407 
409 
424  DLLEXPORT QoreHashNode* getDataSocketInfo(ExceptionSink* xsink, bool host_lookup) const;
425 
427 
433  QoreHashNode* sendControlMessage(const char* cmd, const char* arg, ExceptionSink* xsink);
434 
436 
438  DLLLOCAL void setTimeout(int timeout_ms);
439 
441 
443  DLLLOCAL int getTimeout() const;
444 
446  DLLLOCAL void setEventQueue(ExceptionSink* xsink, Queue* q, QoreValue arg, bool with_data);
447 
449  DLLLOCAL void setDataEventQueue(ExceptionSink* xsink, Queue* q, QoreValue arg, bool with_data);
450 
452  DLLLOCAL void setControlEventQueue(ExceptionSink* xsink, Queue* q, QoreValue arg, bool with_data);
453 
454  DLLLOCAL void cleanup(ExceptionSink *xsink);
455 };
456 
457 #endif // _QORE_OBJECTS_FTPCLIENT_H
OutputStream
Interface for private data of output streams.
Definition: OutputStream.h:44
QoreFtpClient::isDataSecure
DLLEXPORT bool isDataSecure() const
returns the secure data connection parameter flag
QoreFtpClient::getControlSocketInfo
DLLEXPORT QoreHashNode * getControlSocketInfo(ExceptionSink *xsink, bool host_lookup) const
returns information for the current control socket; the socket must be open
QoreFtpClient::setModePORT
DLLEXPORT void setModePORT()
sets the connection mode for the next connection to "PORT"
QoreFtpClient::getURL
DLLEXPORT QoreStringNode * getURL() const
returns a URL string representing the current connection parameters, caller owns the reference count ...
QoreFtpClient::setHostName
DLLEXPORT void setHostName(const char *h)
sets the host name connection parameter
QoreFtpClient::getTimeout
DLLLOCAL int getTimeout() const
returns the socket I/O timeout value as an integer in milliseconds
QoreFtpClient::isSecure
DLLEXPORT bool isSecure() const
returns the secure connection parameter flag
QoreFtpClient::getSSLCipherName
const DLLEXPORT char * getSSLCipherName() const
returns the name of the SSL Cipher for the currently-connected control connection,...
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
QoreFtpClient::get
DLLEXPORT int get(const char *remotepath, const char *localname, ExceptionSink *xsink)
gets a file from the remote server and saves it on the local filesystem
QoreFtpClient::setPort
DLLEXPORT void setPort(int p)
sets the port connection parameter
QoreHashNode
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
QoreFtpClient::getControlPeerInfo
DLLEXPORT QoreHashNode * getControlPeerInfo(ExceptionSink *xsink, bool host_lookup) const
returns peer information for a connected control socket
QoreFtpClient::setTimeout
DLLLOCAL void setTimeout(int timeout_ms)
sets the socket I/O timeout value in milliseconds
QoreFtpClient::setModePASV
DLLEXPORT void setModePASV()
sets the connection mode for the next connection to "PASV" (passive mode)
qore_size_t
size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:73
QoreFtpClient::setUserName
DLLEXPORT void setUserName(const char *u)
sets the user name connection parameter
QoreFtpClient::setInsecureData
DLLEXPORT int setInsecureData()
sets the secure data connection parameter flag
QoreFtpClient::setURL
DLLEXPORT void setURL(const QoreString *url, ExceptionSink *xsink)
sets the connection parameters from a URL
QoreFtpClient::rmdir
DLLEXPORT int rmdir(const char *remotepath, ExceptionSink *xsink)
removes a directory on the remote server
QoreFtpClient::sendControlMessage
QoreHashNode * sendControlMessage(const char *cmd, const char *arg, ExceptionSink *xsink)
Sends a message on the control port and returns a FtpResponseInfo hash or nullptr (if an exception is...
int64
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260
QoreFtpClient::setNetworkFamily
DLLEXPORT void setNetworkFamily(int family)
sets the network family to use with new connections
QoreFtpClient::put
DLLEXPORT int put(const char *localpath, const char *remotename, ExceptionSink *xsink)
sends a file from the local filesystem to the remote server
QoreFtpClient::setEventQueue
DLLLOCAL void setEventQueue(ExceptionSink *xsink, Queue *q, QoreValue arg, bool with_data)
sets the same event queue for data and control sockets
QoreFtpClient::cwd
DLLEXPORT int cwd(const char *dir, ExceptionSink *xsink)
changes the working directory on the remote host
QoreString
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
QoreFtpClient::list
DLLEXPORT QoreStringNode * list(const char *path, bool long_list, ExceptionSink *xsink)
returns a string listing the directory contents on the remote host (caller owns the reference count r...
QoreFtpClient::setModeEPSV
DLLEXPORT void setModeEPSV()
sets the connection mode for the next connection to "EPSV" (extended passive mode)
QoreFtpClient::getDataPeerInfo
DLLEXPORT QoreHashNode * getDataPeerInfo(ExceptionSink *xsink, bool host_lookup) const
returns peer information for a connected data socket
QoreFtpClient::setControlEventQueue
DLLLOCAL void setControlEventQueue(ExceptionSink *xsink, Queue *q, QoreValue arg, bool with_data)
sets the event queue for the control socket
QoreFtpClient::mkdir
DLLEXPORT int mkdir(const char *remotepath, ExceptionSink *xsink)
creates a directory on the remote server
QoreFtpClient::getMode
const DLLEXPORT char * getMode() const
returns a string for the connection mode: "port", "pasv", "epsv", or "auto" if not connected and auto...
QoreFtpClient::~QoreFtpClient
DLLEXPORT ~QoreFtpClient()
disconnects from the host if necessary and frees all memory associated with the object
QoreFtpClient::setSecure
DLLEXPORT int setSecure()
sets the secure connection parameter flag (to use the FTPS protocol)
QoreFtpClient::getAsString
DLLEXPORT QoreStringNode * getAsString(const char *remotepath, ExceptionSink *xsink)
gets a file from the remote server and returns it as a string
InputStream
Interface for private data of input streams.
Definition: InputStream.h:44
QoreFtpClient::setPassword
DLLEXPORT void setPassword(const char *p)
sets the password connection parameter
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
QoreFtpClient::setInsecure
DLLEXPORT int setInsecure()
unsets the secure connection parameter flag (to use the FTP protocol)
QoreFtpClient::priv
hashdecl qore_ftp_private * priv
private implementation of the object
Definition: QoreFtpClient.h:74
QoreFtpClient::getPassword
const DLLEXPORT char * getPassword() const
returns the password connection parameter
QoreFtpClient::disconnect
DLLEXPORT int disconnect()
disconnects from the remote host if connected
QoreFtpClient::getNetworkFamily
DLLEXPORT int getNetworkFamily() const
returns the network family to use with new connections
QoreFtpClient::getSSLCipherVersion
const DLLEXPORT char * getSSLCipherVersion() const
returns the version string of the SSL Cipher for the currently-connected control connection,...
QoreFtpClient::getDataSocketInfo
DLLEXPORT QoreHashNode * getDataSocketInfo(ExceptionSink *xsink, bool host_lookup) const
returns information for the current control socket; the socket must be open
QoreFtpClient::getAsBinary
DLLEXPORT BinaryNode * getAsBinary(const char *remotepath, ExceptionSink *xsink)
gets a file from the remote server and returns it as a binary node
QoreFtpClient::verifyPeerCertificate
DLLEXPORT long verifyPeerCertificate() const
returns the peer certificate verification code
QoreFtpClient
provides thread-safe access to FTP servers through Qore data structures
Definition: QoreFtpClient.h:71
QoreFtpClient::pwd
DLLEXPORT QoreStringNode * pwd(ExceptionSink *xsink)
returns the working directory on the remote host (caller owns the reference count returned)
QoreFtpClient::getPort
DLLEXPORT int getPort() const
returns the port number connection parameter
QoreFtpClient::QoreFtpClient
DLLEXPORT QoreFtpClient()
creates the object with no connection parameters
QoreFtpClient::setModeAuto
DLLEXPORT void setModeAuto()
sets the connection mode for the next connection to "auto"
QoreFtpClient::setDataEventQueue
DLLLOCAL void setDataEventQueue(ExceptionSink *xsink, Queue *q, QoreValue arg, bool with_data)
sets the event queue for the data socket
QoreFtpClient::connect
DLLEXPORT int connect(ExceptionSink *xsink)
connects to the remote host and logs in
BinaryNode
holds arbitrary binary data
Definition: BinaryNode.h:41
QoreFtpClient::getHostName
const DLLEXPORT char * getHostName() const
returns the hostname connection parameter
QoreFtpClient::del
DLLEXPORT int del(const char *file, ExceptionSink *xsink)
deletes the given file on the remote server
QoreStringNode
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
QoreFtpClient::operator=
DLLLOCAL QoreFtpClient & operator=(const QoreFtpClient &)
this function is not implemented; it is here as a private function in order to prohibit it from being...
QoreFtpClient::getUserName
const DLLEXPORT char * getUserName() const
returns the user name connection parameter
QoreFtpClient::putData
DLLEXPORT int putData(const void *data, qore_size_t len, const char *remotename, ExceptionSink *xsink)
sends a file data io the remote server
QoreFtpClient::rename
DLLEXPORT int rename(const char *from, const char *to, ExceptionSink *xsink)
renames/moves a file on the remote server