QoreFtpClient.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreFtpClient.h
thread-safe Qore QoreFtpClient object
Qore Programming Language
Copyright (C) 2003 - 2022 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_QOREFTPCLIENT_H
#define _QORE_QOREFTPCLIENT_H
#include <qore/InputStream.h>
#include <qore/OutputStream.h>
#define DEFAULT_FTP_CONTROL_PORT 21
#define DEFAULT_FTP_DATA_PORT 20
#define DEFAULT_USERNAME "anonymous"
#define DEFAULT_PASSWORD "qore@nohost.com"
class FtpResp;
class Queue;
class QoreFtpClient {
protected:
struct qore_ftp_private *priv;
DLLLOCAL QoreFtpClient(const QoreFtpClient&);
DLLLOCAL QoreFtpClient& operator=(const QoreFtpClient&);
public:
DLLEXPORT QoreFtpClient(const QoreString *url, ExceptionSink* xsink);
DLLEXPORT QoreFtpClient();
DLLEXPORT ~QoreFtpClient();
DLLEXPORT int connect(ExceptionSink* xsink);
DLLEXPORT int disconnect();
DLLEXPORT int cwd(const char* dir, ExceptionSink* xsink);
DLLEXPORT QoreStringNode* pwd(ExceptionSink* xsink);
DLLEXPORT int put(const char* localpath, const char* remotename, ExceptionSink* xsink);
DLLEXPORT int put(InputStream* is, const char* remotename, ExceptionSink* xsink);
DLLEXPORT int get(const char* remotepath, const char* localname, ExceptionSink* xsink);
DLLEXPORT int get(const char* remotepath, OutputStream* os, ExceptionSink* xsink);
DLLEXPORT int putData(const void* data, size_t len, const char* remotename, ExceptionSink* xsink);
DLLEXPORT QoreStringNode* getAsString(const char* remotepath, ExceptionSink* xsink);
DLLEXPORT QoreStringNode* getAsString(ExceptionSink* xsink, const char* remotepath,
const QoreEncoding* encoding = QCS_DEFAULT);
DLLEXPORT BinaryNode* getAsBinary(const char* remotepath, ExceptionSink* xsink);
DLLEXPORT int rename(const char* from, const char* to, ExceptionSink* xsink);
DLLEXPORT QoreStringNode* list(const char* path, bool long_list, ExceptionSink* xsink);
DLLEXPORT int del(const char* file, ExceptionSink* xsink);
DLLEXPORT int mkdir(const char* remotepath, ExceptionSink* xsink);
DLLEXPORT int rmdir(const char* remotepath, ExceptionSink* xsink);
DLLEXPORT int getPort() const;
DLLEXPORT const char* getUserName() const;
DLLEXPORT const char* getPassword() const;
DLLEXPORT const char* getHostName() const;
DLLEXPORT void setURL(const QoreString *url, ExceptionSink* xsink);
DLLEXPORT QoreStringNode* getURL() const;
DLLEXPORT void setPort(int p);
DLLEXPORT void setUserName(const char* u);
DLLEXPORT void setPassword(const char* p);
DLLEXPORT void setHostName(const char* h);
DLLEXPORT int setSecure();
DLLEXPORT int setInsecure();
DLLEXPORT int setInsecureData();
DLLEXPORT bool isSecure() const;
DLLEXPORT bool isDataSecure() const;
DLLEXPORT const char* getSSLCipherName() const;
DLLEXPORT const char* getSSLCipherVersion() const;
DLLEXPORT long verifyPeerCertificate() const;
DLLEXPORT void setModeAuto();
DLLEXPORT void setModeEPSV();
DLLEXPORT void setModePASV();
DLLEXPORT void setModePORT();
DLLEXPORT const char* getMode() const;
DLLEXPORT void clearWarningQueue(ExceptionSink* xsink);
DLLEXPORT void setWarningQueue(ExceptionSink* xsink, int64 warning_ms, int64 warning_bs, Queue* wq, QoreValue arg, int64 min_ms = 1000);
DLLEXPORT QoreHashNode* getUsageInfo() const;
DLLEXPORT void clearStats();
DLLEXPORT void setNetworkFamily(int family);
DLLEXPORT int getNetworkFamily() const;
DLLEXPORT QoreHashNode* getControlPeerInfo(ExceptionSink* xsink, bool host_lookup) const;
DLLEXPORT QoreHashNode* getDataPeerInfo(ExceptionSink* xsink, bool host_lookup) const;
DLLEXPORT QoreHashNode* getControlSocketInfo(ExceptionSink* xsink, bool host_lookup) const;
DLLEXPORT QoreHashNode* getDataSocketInfo(ExceptionSink* xsink, bool host_lookup) const;
QoreHashNode* sendControlMessage(const char* cmd, const char* arg, ExceptionSink* xsink);
DLLLOCAL void setTimeout(int timeout_ms);
DLLLOCAL int getTimeout() const;
DLLLOCAL void setEventQueue(ExceptionSink* xsink, Queue* q, QoreValue arg, bool with_data);
DLLLOCAL void setDataEventQueue(ExceptionSink* xsink, Queue* q, QoreValue arg, bool with_data);
DLLLOCAL void setControlEventQueue(ExceptionSink* xsink, Queue* q, QoreValue arg, bool with_data);
DLLLOCAL void cleanup(ExceptionSink* xsink);
};
#endif // _QORE_OBJECTS_FTPCLIENT_H
QoreFtpClient::mkdir
DLLEXPORT int mkdir(const char *remotepath, ExceptionSink *xsink)
creates a directory on the remote server
QoreFtpClient::priv
struct qore_ftp_private * priv
private implementation of the object
Definition: QoreFtpClient.h:74
QoreEncoding
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
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::getDataPeerInfo
DLLEXPORT QoreHashNode * getDataPeerInfo(ExceptionSink *xsink, bool host_lookup) const
returns peer information for a connected data socket
QoreFtpClient::setModeEPSV
DLLEXPORT void setModeEPSV()
sets the connection mode for the next connection to "EPSV" (extended passive mode) ...
QoreFtpClient::disconnect
DLLEXPORT int disconnect()
disconnects from the remote host if connected
QoreHashNode
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:50
QoreFtpClient::getMode
DLLEXPORT const char * getMode() const
returns a string for the connection mode: "port", "pasv", "epsv", or "auto" if not connected and auto...
QCS_DEFAULT
DLLEXPORT const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
QoreFtpClient::setInsecure
DLLEXPORT int setInsecure()
unsets the secure connection parameter flag (to use the FTP protocol)
QoreFtpClient::getDataSocketInfo
DLLEXPORT QoreHashNode * getDataSocketInfo(ExceptionSink *xsink, bool host_lookup) const
returns information for the current control socket; the socket must be open
QoreFtpClient::QoreFtpClient
DLLEXPORT QoreFtpClient()
creates the object with no connection parameters
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::getNetworkFamily
DLLEXPORT int getNetworkFamily() const
returns the network family to use with new connections
QoreFtpClient::~QoreFtpClient
DLLEXPORT ~QoreFtpClient()
disconnects from the host if necessary and frees all memory associated with the object ...
QoreFtpClient::getAsString
DLLEXPORT QoreStringNode * getAsString(const char *remotepath, ExceptionSink *xsink)
gets a file from the remote server and returns it as a string
QoreFtpClient::setPassword
DLLEXPORT void setPassword(const char *p)
sets the password connection parameter
QoreFtpClient::getSSLCipherVersion
DLLEXPORT const char * getSSLCipherVersion() const
returns the version string of the SSL Cipher for the currently-connected control connection, or 0 if there is none
QoreFtpClient::setModeAuto
DLLEXPORT void setModeAuto()
sets the connection mode for the next connection to "auto"
QoreFtpClient
provides thread-safe access to FTP servers through Qore data structures
Definition: QoreFtpClient.h:71
QoreFtpClient::verifyPeerCertificate
DLLEXPORT long verifyPeerCertificate() const
returns the peer certificate verification code
QoreFtpClient::pwd
DLLEXPORT QoreStringNode * pwd(ExceptionSink *xsink)
returns the working directory on the remote host (caller owns the reference count returned) ...
QoreFtpClient::getSSLCipherName
DLLEXPORT const char * getSSLCipherName() const
returns the name of the SSL Cipher for the currently-connected control connection, or 0 if there is none
QoreFtpClient::getPort
DLLEXPORT int getPort() const
returns the port number connection parameter
OutputStream
Interface for private data of output streams.
Definition: OutputStream.h:44
QoreString
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:93
QoreStringNode
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
QoreFtpClient::setDataEventQueue
DLLLOCAL void setDataEventQueue(ExceptionSink *xsink, Queue *q, QoreValue arg, bool with_data)
sets the event queue for the data socket
QoreFtpClient::setHostName
DLLEXPORT void setHostName(const char *h)
sets the host name connection parameter
QoreFtpClient::del
DLLEXPORT int del(const char *file, ExceptionSink *xsink)
deletes the given file on the remote server
QoreFtpClient::connect
DLLEXPORT int connect(ExceptionSink *xsink)
connects to the remote host and logs in
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...
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:275
QoreFtpClient::putData
DLLEXPORT int putData(const void *data, size_t len, const char *remotename, ExceptionSink *xsink)
sends a file data io the remote server
QoreFtpClient::setModePASV
DLLEXPORT void setModePASV()
sets the connection mode for the next connection to "PASV" (passive mode)
QoreFtpClient::getURL
DLLEXPORT QoreStringNode * getURL() const
returns a URL string representing the current connection parameters, caller owns the reference count ...
QoreFtpClient::setInsecureData
DLLEXPORT int setInsecureData()
sets the secure data connection parameter flag
QoreFtpClient::rename
DLLEXPORT int rename(const char *from, const char *to, ExceptionSink *xsink)
renames/moves a file on the remote server
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
QoreFtpClient::setTimeout
DLLLOCAL void setTimeout(int timeout_ms)
sets the socket I/O timeout value in milliseconds
QoreFtpClient::getTimeout
DLLLOCAL int getTimeout() const
returns the socket I/O timeout value as an integer in milliseconds
InputStream
Interface for private data of input streams.
Definition: InputStream.h:44
QoreFtpClient::isDataSecure
DLLEXPORT bool isDataSecure() const
returns the secure data connection parameter flag
QoreFtpClient::getControlPeerInfo
DLLEXPORT QoreHashNode * getControlPeerInfo(ExceptionSink *xsink, bool host_lookup) const
returns peer information for a connected control socket
QoreFtpClient::setPort
DLLEXPORT void setPort(int p)
sets the port connection parameter
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::setModePORT
DLLEXPORT void setModePORT()
sets the connection mode for the next connection to "PORT"
QoreFtpClient::getHostName
DLLEXPORT const char * getHostName() const
returns the hostname connection parameter
QoreFtpClient::setNetworkFamily
DLLEXPORT void setNetworkFamily(int family)
sets the network family to use with new connections
QoreFtpClient::getControlSocketInfo
DLLEXPORT QoreHashNode * getControlSocketInfo(ExceptionSink *xsink, bool host_lookup) const
returns information for the current control socket; the socket must be open
QoreFtpClient::isSecure
DLLEXPORT bool isSecure() const
returns the secure connection parameter flag
QoreFtpClient::setControlEventQueue
DLLLOCAL void setControlEventQueue(ExceptionSink *xsink, Queue *q, QoreValue arg, bool with_data)
sets the event queue for the control socket
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::setURL
DLLEXPORT void setURL(const QoreString *url, ExceptionSink *xsink)
sets the connection parameters from a URL
QoreFtpClient::getPassword
DLLEXPORT const char * getPassword() const
returns the password connection parameter
QoreFtpClient::setUserName
DLLEXPORT void setUserName(const char *u)
sets the user name connection parameter
QoreFtpClient::getUserName
DLLEXPORT const char * getUserName() const
returns the user name connection parameter
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::setSecure
DLLEXPORT int setSecure()
sets the secure connection parameter flag (to use the FTPS protocol)
QoreFtpClient::rmdir
DLLEXPORT int rmdir(const char *remotepath, ExceptionSink *xsink)
removes a directory on the remote server
QoreFtpClient::cwd
DLLEXPORT int cwd(const char *dir, ExceptionSink *xsink)
changes the working directory on the remote host
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...
BinaryNode
holds arbitrary binary data
Definition: BinaryNode.h:41