1018 lines
37 KiB
C++
1018 lines
37 KiB
C++
/**
|
|
* @file include/ActivMiddleware/Misc/CurlFtpHelper.h
|
|
*
|
|
* @brief Header file for the curl FTP helper class which uses cUrl and ftpparser.
|
|
*
|
|
* When using this file you will need to link to the curl library (CurlPackage_x86_win32_vc71_mdid.lib etc.).
|
|
*/
|
|
|
|
#if (!defined ACTIV_MISC_CURL_FTP_HELPER_H)
|
|
#define ACTIV_MISC_CURL_FTP_HELPER_H
|
|
|
|
#include "ActivMiddleware/ActivBase/StatusCodeException.h"
|
|
#include "ActivMiddleware/ActivBase/OsException.h"
|
|
#include "ActivMiddleware/ActivBase/MessageRateThrottler.h"
|
|
#include "ActivMiddleware/ActivBase/File.h"
|
|
#include "ActivMiddleware/Misc/FtpParse.h"
|
|
#include "ActivMiddleware/Misc/Fmt.h"
|
|
#include "ActivMiddleware/Misc/CrtHelper.h"
|
|
#include "ActivMiddleware/CxxYZ/regex.h"
|
|
|
|
#include <curl/curl.h>
|
|
|
|
#include "IFtpHelper.h"
|
|
|
|
#include <vector>
|
|
#include <time.h>
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
/**
|
|
* @brief CurlFtpHelper class.
|
|
*/
|
|
class CurlFtpHelper : public IFtpHelper
|
|
{
|
|
public:
|
|
|
|
/**
|
|
* @brief CurlInitializeHelper class.
|
|
*/
|
|
class CurlInitializeHelper
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Constuctor
|
|
*/
|
|
CurlInitializeHelper();
|
|
|
|
/**
|
|
* @brief Destructor
|
|
*/
|
|
~CurlInitializeHelper();
|
|
};
|
|
|
|
/**
|
|
* @brief Constuctor
|
|
*
|
|
* @param server the name of the ftp server.
|
|
* @param username the user name if required.
|
|
* @param password the password if required.
|
|
* @param port the ftp port to connect to.
|
|
* @param isEpsv to enable/disable epsv.
|
|
* @param isPort to enable disable active or passive modes.
|
|
* @param isEprt to enable eprt mode.
|
|
* @param curlLogFilename for detail curl ftp log.
|
|
* @param timeout the global timeout for any operation.
|
|
* @param lowSpeedLimit the low speed limit before timing out.
|
|
* @param lowSpeedTime the low speed limit time before timing out.
|
|
* @param connectTimeout the timeout for the connect command.
|
|
* @param isSftp to enable/disable sftp.
|
|
* @param shouldUseFreshConnect whether to use a new (fresh) connection or not.
|
|
* @param shouldForbidReuse whether to forbid curl from reusing a connection.
|
|
* @param maxTransferRate the maximum rate in kB at which to transfer files, 0 is unlimited.
|
|
* @param shouldEscapeUrls whether to escape # characters in urls.
|
|
*/
|
|
CurlFtpHelper(const String &server, const String &username = "", const String &password = "", const uint32_t port = IFtpHelper::DEFAULT_FTP_PORT, const bool isEpsv = false, const bool isPort = false, const bool isEprt = false, const String &curlLogFilename = "", const uint32_t timeout = IFtpHelper::DEFAULT_FTP_TIMEOUT, const uint32_t lowSpeedLimit = IFtpHelper::DEFAULT_FTP_LOW_SPEED_LIMIT, const uint32_t lowSpeedTime = IFtpHelper::DEFAULT_FTP_LOW_SPEED_TIME, const uint32_t connectTimeout = IFtpHelper::DEFAULT_FTP_CONNECT_TIMEOUT, const bool isSftp = false, const bool shouldUseFreshConnect = false, const bool shouldForbidReuse = false, const size_t maxTransferRate = 0, const bool shouldEscapeUrls = false);
|
|
|
|
virtual ~CurlFtpHelper() ACTIV_OVERRIDE;
|
|
|
|
virtual StatusCodeHelper Connect() ACTIV_OVERRIDE;
|
|
virtual StatusCodeHelper Disconnect() ACTIV_OVERRIDE;
|
|
virtual StatusCodeHelper GetFileList(FileInfoList &fileInfoList, const String &remoteDirectory = "") ACTIV_OVERRIDE;
|
|
virtual StatusCodeHelper GetFile(const String &remoteFilename, const String &localFilename, const String &remoteDirectory = "") ACTIV_OVERRIDE;
|
|
virtual StatusCodeHelper PutFile(const String &localFilename, const String &remoteFilename, const String &remoteDirectory = "") ACTIV_OVERRIDE;
|
|
virtual StatusCodeHelper PutAndRenameFile(const String &localFilename, const String &remoteFilename, const String &remoteDirectory = "", const String &intermediateFilename = "", const String &intermediateDirectory = "") ACTIV_OVERRIDE;
|
|
virtual StatusCodeHelper RenameFile(const String &sourceFilename, const String &targetFilename, const String &sourceDirectory = "", const String &targetDirectory = "") ACTIV_OVERRIDE;
|
|
virtual StatusCodeHelper DeleteFile(const String &remoteFilename, const String &remoteDirectory = "") ACTIV_OVERRIDE;
|
|
virtual StatusCodeHelper DeleteFile(const FileInfoList &fileInfoList, const String &remoteDirectory = "") ACTIV_OVERRIDE;
|
|
virtual StatusCodeHelper GetAndDeleteFile(const String &remoteFilename, const String &localFilename, const String &remoteDirectory = "") ACTIV_OVERRIDE;
|
|
|
|
virtual bool IsConnected() const ACTIV_OVERRIDE;
|
|
|
|
/**
|
|
* @brief Set functions
|
|
*/
|
|
void SetTimeout(const uint32_t timeout);
|
|
void SetLowSpeedLimit(const uint32_t lowSpeedLimit);
|
|
void SetLowSpeedTime(const uint32_t lowSpeedTime);
|
|
void SetEpsv(const bool isEpsv);
|
|
void SetPort(const bool isPort);
|
|
void SetEprt(const bool isEprt);
|
|
void SetCurlLogFilename(const String &logFilename);
|
|
void SetConnectTimeout(const uint32_t connectTimeout);
|
|
void SetSftp(const bool isSftp);
|
|
void SetMaxTransferRate(const size_t &rate);
|
|
|
|
/**
|
|
* @brief Get functions
|
|
*/
|
|
uint32_t GetTimeout() const;
|
|
uint32_t GetLowSpeedLimit() const;
|
|
uint32_t GetLowSpeedTime() const;
|
|
bool GetUseEpsv() const;
|
|
uint32_t GetConnectTimeout() const;
|
|
bool GetIsSftp() const;
|
|
size_t GetMaxTransferRate() const;
|
|
|
|
/**
|
|
* @brief Initialize the curl lib, once per app
|
|
*/
|
|
static void Initialize();
|
|
|
|
/**
|
|
* @brief CleanUp the curl lib, once per app
|
|
*/
|
|
static void CleanUp();
|
|
|
|
private:
|
|
|
|
class CallbackData
|
|
{
|
|
public:
|
|
CallbackData(const size_t rate = 0);
|
|
virtual ~CallbackData();
|
|
virtual size_t AppendData(void *ptr, size_t size);
|
|
virtual void Throttle(const size_t size);
|
|
|
|
private:
|
|
MessageRateThrottler m_messageRateThrottler;
|
|
size_t m_totalBytes;
|
|
size_t m_lastSuspendByteCount;
|
|
};
|
|
|
|
class FileListCallbackData : public CallbackData
|
|
{
|
|
public:
|
|
virtual size_t AppendData(void *ptr, size_t size) ACTIV_OVERRIDE;
|
|
StatusCodeHelper GetFileList(FileInfoList &fileInfoList, bool includeDirectories);
|
|
|
|
private:
|
|
String m_data;
|
|
};
|
|
|
|
class GetFileCallbackData : CallbackData
|
|
{
|
|
public:
|
|
GetFileCallbackData(const String &filename, const size_t rateLimit = 0);
|
|
virtual size_t AppendData(void *ptr, size_t size) ACTIV_OVERRIDE;
|
|
|
|
private:
|
|
File m_file;
|
|
};
|
|
|
|
class PutFileCallbackData : CallbackData
|
|
{
|
|
public:
|
|
PutFileCallbackData(const String &filename, const size_t rateLimit = 0);
|
|
virtual size_t AppendData(void *ptr, size_t size) ACTIV_OVERRIDE;
|
|
|
|
private:
|
|
File m_file;
|
|
};
|
|
|
|
static size_t CallbackFunction(void *ptr, size_t size, size_t nmemb, void *stream);
|
|
|
|
String GetUrl(String path = "") const;
|
|
|
|
CURL *m_pCurl; ///< The curl "easy" handle.
|
|
bool m_isEpsv; ///< To use EPSV or not
|
|
bool m_isPort; ///< To use PORT or not
|
|
bool m_isEprt; ///< To use EPRT or not
|
|
FILE *m_pCurlLogFileHandle; ///< Curl's internal log
|
|
uint32_t m_timeout; ///< Maximum time in seconds that you allow the libcurl transfer operation to take
|
|
uint32_t m_lowSpeedLimit; ///< The transfer speed in bytes per second that the transfer should be below during CURLOPT_LOW_SPEED_TIME seconds for the library to consider it too slow and abort.
|
|
uint32_t m_lowSpeedTime; ///< It contains the time in seconds that the transfer should be below the CURLOPT_LOW_SPEED_LIMIT for the library to consider it too slow and abort.
|
|
uint32_t m_connectTimeout; ///< It should contain the maximum time in seconds that you allow the connection to the server to take. This only limits the connection phase, once it has connected, this option is of no more use.
|
|
bool m_isSftp; ///< To use SFTP or not.
|
|
bool m_shouldUseFreshConnect; ///< Whether to use a new (fresh) connection or not.
|
|
bool m_shouldForbidReuse; ///< Whether to forbid curl from reusing a connection.
|
|
size_t m_maxTransferRate; ///< The max transfer rate in bytes.
|
|
bool m_shouldEscapeUrls; ///< Whether to escape urls.
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline CurlFtpHelper::CurlInitializeHelper::CurlInitializeHelper()
|
|
{
|
|
CurlFtpHelper::Initialize();
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline CurlFtpHelper::CurlInitializeHelper::~CurlInitializeHelper()
|
|
{
|
|
CurlFtpHelper::CleanUp();
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void CurlFtpHelper::Initialize()
|
|
{
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void CurlFtpHelper::CleanUp()
|
|
{
|
|
curl_global_cleanup();
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline CurlFtpHelper::CurlFtpHelper(const String &server, const String &username, const String &password, const uint32_t port, const bool isEpsv, const bool isPort, const bool isEprt, const String &curlLogFilename, const uint32_t timeout, const uint32_t lowSpeedLimit, const uint32_t lowSpeedTime, const uint32_t connectTimeout, const bool isSftp, const bool shouldUseFreshConnect, const bool shouldForbidReuse, const size_t maxTransferRate, const bool shouldEscapeUrls) :
|
|
IFtpHelper(server, username, password, port),
|
|
m_pCurl(0),
|
|
m_isEpsv(isEpsv),
|
|
m_isPort(isPort),
|
|
m_isEprt(isEprt),
|
|
m_pCurlLogFileHandle(0),
|
|
m_timeout(timeout),
|
|
m_lowSpeedLimit(lowSpeedLimit),
|
|
m_lowSpeedTime(lowSpeedTime),
|
|
m_connectTimeout(connectTimeout),
|
|
m_isSftp(isSftp),
|
|
m_shouldUseFreshConnect(shouldUseFreshConnect),
|
|
m_shouldForbidReuse(shouldForbidReuse),
|
|
m_maxTransferRate(maxTransferRate),
|
|
m_shouldEscapeUrls(shouldEscapeUrls)
|
|
{
|
|
char *pEscapedUsername = curl_escape(username.c_str(), static_cast<int>(username.size()));
|
|
char *pEscapedPassword = curl_escape(password.c_str(), static_cast<int>(password.size()));
|
|
|
|
m_username = String(pEscapedUsername);
|
|
m_password = String(pEscapedPassword);
|
|
|
|
curl_free(pEscapedUsername);
|
|
curl_free(pEscapedPassword);
|
|
|
|
if ("" != curlLogFilename)
|
|
m_pCurlLogFileHandle = fopen(curlLogFilename.c_str(), "a+");
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline CurlFtpHelper::~CurlFtpHelper()
|
|
{
|
|
Disconnect();
|
|
if (m_pCurlLogFileHandle)
|
|
fclose(m_pCurlLogFileHandle);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline bool CurlFtpHelper::IsConnected() const
|
|
{
|
|
return (0 != m_pCurl);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline String CurlFtpHelper::GetUrl(String path) const
|
|
{
|
|
if (m_shouldEscapeUrls && !path.empty())
|
|
{
|
|
String escapedPath;
|
|
CxxYZ::regex_replace(std::back_inserter(escapedPath), path.begin(), path.end(), CxxYZ::regex("#"), "%23");
|
|
path = escapedPath;
|
|
}
|
|
|
|
if (m_isSftp)
|
|
return "sftp://" + m_username + ":" + m_password + "@" + m_server + ":" + TypeToString(m_port) + "/" + path;
|
|
|
|
return "ftp://" + m_username + ":" + m_password + "@" + m_server + ":" + TypeToString(m_port) + "/" + path;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCodeHelper CurlFtpHelper::Connect()
|
|
{
|
|
if (IsConnected())
|
|
return StatusCodeHelper(STATUS_CODE_ALREADY_CONNECTED);
|
|
|
|
m_pCurl = curl_easy_init();
|
|
|
|
if (0 == m_pCurl)
|
|
return StatusCodeHelper(STATUS_CODE_FAILURE, "failed to to initialize curl");
|
|
try
|
|
{
|
|
const String url = GetUrl();
|
|
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_URL, url.c_str()));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_NOPROGRESS, 1));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_NOBODY, 1));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_WRITEFUNCTION, CallbackFunction));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_READFUNCTION, CallbackFunction));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_TIMEOUT, m_timeout));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_LOW_SPEED_LIMIT, m_lowSpeedLimit));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_LOW_SPEED_TIME, m_lowSpeedTime));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_CONNECTTIMEOUT, m_connectTimeout));
|
|
|
|
// Epsv is enabled by curl so we disable it.
|
|
if (!m_isEpsv)
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_FTP_USE_EPSV, 0));
|
|
|
|
if (m_isPort)
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_FTPPORT, "-"));
|
|
|
|
if (m_isEprt)
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_FTP_USE_EPRT, 1));
|
|
|
|
if (m_shouldUseFreshConnect)
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_FRESH_CONNECT, 1));
|
|
|
|
if (m_shouldForbidReuse)
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_FORBID_REUSE, 1));
|
|
|
|
if (NULL != m_pCurlLogFileHandle)
|
|
{
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_STDERR , m_pCurlLogFileHandle));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_VERBOSE , 1));
|
|
}
|
|
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_perform(m_pCurl));
|
|
}
|
|
catch (const Exception &e)
|
|
{
|
|
Disconnect();
|
|
return StatusCodeHelper(STATUS_CODE_FAILURE, curl_easy_strerror(static_cast<CURLcode>(e.m_errorCode)));
|
|
}
|
|
|
|
return StatusCodeHelper(STATUS_CODE_SUCCESS);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCodeHelper CurlFtpHelper::Disconnect()
|
|
{
|
|
if (!IsConnected())
|
|
return StatusCodeHelper(STATUS_CODE_NOT_CONNECTED);
|
|
|
|
if (0 != m_pCurl)
|
|
curl_easy_cleanup(m_pCurl);
|
|
|
|
m_pCurl = 0;
|
|
|
|
return StatusCodeHelper(STATUS_CODE_SUCCESS);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCodeHelper CurlFtpHelper::GetFileList(FileInfoList &fileinfoList, const String &remoteDirectory)
|
|
{
|
|
if (!IsConnected())
|
|
return StatusCodeHelper(STATUS_CODE_NOT_CONNECTED);
|
|
|
|
FileListCallbackData fileListCallBackData;
|
|
|
|
try
|
|
{
|
|
const String url = (remoteDirectory.empty() ? GetUrl() : GetUrl(remoteDirectory + "/"));
|
|
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_URL, url.c_str()));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_NOBODY, 0));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_WRITEDATA, &fileListCallBackData));
|
|
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_perform(m_pCurl));
|
|
}
|
|
catch (const Exception &e)
|
|
{
|
|
if (CURLE_COULDNT_CONNECT == e.m_errorCode)
|
|
Disconnect();
|
|
|
|
return StatusCodeHelper(STATUS_CODE_FAILURE, curl_easy_strerror(static_cast<CURLcode>(e.m_errorCode)));
|
|
}
|
|
|
|
return fileListCallBackData.GetFileList(fileinfoList, false);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCodeHelper CurlFtpHelper::GetFile(const String &remoteFilename, const String &localFilename, const String &remoteDirectory)
|
|
{
|
|
if (!IsConnected())
|
|
return StatusCodeHelper(STATUS_CODE_NOT_CONNECTED);
|
|
|
|
GetFileCallbackData getFileCallbackData(localFilename, m_maxTransferRate);
|
|
|
|
try
|
|
{
|
|
const String url = (remoteDirectory.empty() ? GetUrl(remoteFilename) : GetUrl(remoteDirectory + "/" + remoteFilename));
|
|
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_URL, url.c_str()));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_NOBODY, 0));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_WRITEDATA, &getFileCallbackData));
|
|
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_perform(m_pCurl));
|
|
}
|
|
catch (const Exception &e)
|
|
{
|
|
if (CURLE_COULDNT_CONNECT == e.m_errorCode)
|
|
Disconnect();
|
|
|
|
return StatusCodeHelper(STATUS_CODE_FAILURE, curl_easy_strerror(static_cast<CURLcode>(e.m_errorCode)));
|
|
}
|
|
|
|
return StatusCodeHelper(STATUS_CODE_SUCCESS);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCodeHelper CurlFtpHelper::PutFile(const String &localFilename, const String &remoteFilename, const String &remoteDirectory)
|
|
{
|
|
if (!IsConnected())
|
|
return StatusCodeHelper(STATUS_CODE_NOT_CONNECTED);
|
|
|
|
uint64_t fileSize = 0;
|
|
StatusCode statusCode = File::GetSize(localFilename, fileSize);
|
|
if (STATUS_CODE_SUCCESS != statusCode)
|
|
return StatusCodeHelper(statusCode, "Failed to retrieve file size.");
|
|
|
|
PutFileCallbackData putFileCallbackData(localFilename, m_maxTransferRate);
|
|
|
|
try
|
|
{
|
|
const String url = (remoteDirectory.empty() ? GetUrl(remoteFilename) : GetUrl(remoteDirectory + "/" + remoteFilename));
|
|
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_URL, url.c_str()));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_READDATA, &putFileCallbackData));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_NOBODY, 0));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_UPLOAD, 1L));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_INFILESIZE_LARGE, fileSize));
|
|
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_perform(m_pCurl));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_UPLOAD, 0));
|
|
}
|
|
catch (const Exception &e)
|
|
{
|
|
curl_easy_setopt(m_pCurl, CURLOPT_UPLOAD, 0);
|
|
|
|
if (CURLE_COULDNT_CONNECT == e.m_errorCode)
|
|
Disconnect();
|
|
|
|
return StatusCodeHelper(STATUS_CODE_FAILURE, curl_easy_strerror(static_cast<CURLcode>(e.m_errorCode)));
|
|
}
|
|
|
|
return StatusCodeHelper(STATUS_CODE_SUCCESS);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCodeHelper CurlFtpHelper::PutAndRenameFile(const String &localFilename, const String &remoteFilename, const String &remoteDirectory, const String &intermediateFilename, const String &intermediateDirectory)
|
|
{
|
|
if (!IsConnected())
|
|
return StatusCodeHelper(STATUS_CODE_NOT_CONNECTED);
|
|
|
|
uint64_t fileSize = 0;
|
|
StatusCode statusCode = File::GetSize(localFilename, fileSize);
|
|
if (STATUS_CODE_SUCCESS != statusCode)
|
|
return StatusCodeHelper(statusCode, "Failed to retrieve file size.");
|
|
|
|
PutFileCallbackData putFileCallbackData(localFilename, m_maxTransferRate);
|
|
|
|
// The ftp server has cwd'd to the remote dir prior to file pushing so no dir required on source because it's already in
|
|
// dir with file we are renaming. Hack is to work out path back to root to prepend to the rename target dir.
|
|
|
|
String intermediatePath = (intermediateDirectory.empty() ? intermediateFilename : intermediateDirectory + "/" + intermediateFilename);
|
|
String remotePath = (remoteDirectory.empty() ? remoteFilename : remoteDirectory + "/" + remoteFilename);
|
|
|
|
if (remoteDirectory.find('/') != 0)
|
|
{
|
|
size_t pos = intermediatePath.find('/');
|
|
while (String::npos != pos)
|
|
{
|
|
remotePath.insert(0, String("../"));
|
|
pos = intermediatePath.find('/', ++pos);
|
|
}
|
|
}
|
|
|
|
String renameSourceString("RNFR " + intermediateFilename);
|
|
String renameTargetString("RNTO " + remotePath);
|
|
struct curl_slist *headerlist = 0;
|
|
headerlist = curl_slist_append(headerlist, renameSourceString.c_str());
|
|
headerlist = curl_slist_append(headerlist, renameTargetString.c_str());
|
|
|
|
try
|
|
{
|
|
const String url = (intermediateDirectory.empty() ? GetUrl(intermediateFilename) : GetUrl(intermediateDirectory + "/" + intermediateFilename));
|
|
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_URL, url.c_str()));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_READDATA, &putFileCallbackData));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_NOBODY, 0));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_UPLOAD, 1L));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_INFILESIZE_LARGE, fileSize));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_POSTQUOTE, headerlist));
|
|
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_perform(m_pCurl));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_UPLOAD, 0));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_POSTQUOTE, 0));
|
|
curl_slist_free_all(headerlist);
|
|
}
|
|
catch (const Exception &e)
|
|
{
|
|
curl_easy_setopt(m_pCurl, CURLOPT_UPLOAD, 0);
|
|
curl_easy_setopt(m_pCurl, CURLOPT_POSTQUOTE, 0);
|
|
curl_slist_free_all(headerlist);
|
|
|
|
if (CURLE_COULDNT_CONNECT == e.m_errorCode)
|
|
Disconnect();
|
|
|
|
return StatusCodeHelper(STATUS_CODE_FAILURE, curl_easy_strerror(static_cast<CURLcode>(e.m_errorCode)));
|
|
}
|
|
|
|
return StatusCodeHelper(STATUS_CODE_SUCCESS);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCodeHelper CurlFtpHelper::RenameFile(const String &sourceFilename, const String &targetFilename, const String &sourceDirectory, const String &targetDirectory)
|
|
{
|
|
if (!IsConnected())
|
|
return StatusCodeHelper(STATUS_CODE_NOT_CONNECTED);
|
|
|
|
String sourcePath = (sourceDirectory.empty() ? sourceFilename : sourceDirectory + "/" + sourceFilename);
|
|
String remotePath = (targetDirectory.empty() ? targetFilename : targetDirectory + "/" + targetFilename);
|
|
|
|
String renameSourceString("RNFR " + sourcePath);
|
|
String renameTargetString("RNTO " + remotePath);
|
|
struct curl_slist *headerlist = 0;
|
|
headerlist = curl_slist_append(headerlist, renameSourceString.c_str());
|
|
headerlist = curl_slist_append(headerlist, renameTargetString.c_str());
|
|
|
|
try
|
|
{
|
|
const String url = GetUrl();
|
|
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_URL, url.c_str()));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_NOBODY, 1));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_QUOTE, headerlist));
|
|
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_perform(m_pCurl));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_QUOTE, 0));
|
|
curl_slist_free_all(headerlist);
|
|
}
|
|
catch (const Exception &e)
|
|
{
|
|
curl_easy_setopt(m_pCurl, CURLOPT_QUOTE, 0);
|
|
curl_slist_free_all(headerlist);
|
|
|
|
if (CURLE_COULDNT_CONNECT == e.m_errorCode)
|
|
Disconnect();
|
|
|
|
return StatusCodeHelper(STATUS_CODE_FAILURE, curl_easy_strerror(static_cast<CURLcode>(e.m_errorCode)));
|
|
}
|
|
|
|
return StatusCodeHelper(STATUS_CODE_SUCCESS);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCodeHelper CurlFtpHelper::DeleteFile(const String &remoteFilename, const String &remoteDirectory)
|
|
{
|
|
if (!IsConnected())
|
|
return StatusCodeHelper(STATUS_CODE_NOT_CONNECTED);
|
|
|
|
struct curl_slist *list = 0;
|
|
|
|
try
|
|
{
|
|
String ftpCommand;
|
|
|
|
if (m_isSftp)
|
|
ftpCommand = "rm /" + remoteDirectory + "/" + remoteFilename;
|
|
else
|
|
ftpCommand = "DELE " + remoteFilename;
|
|
|
|
list = curl_slist_append(list, ftpCommand.c_str());
|
|
|
|
const String url = (remoteDirectory.empty() ? GetUrl() : GetUrl(remoteDirectory + "/"));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_URL, url.c_str()));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_NOBODY, 1));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_QUOTE, list));
|
|
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_perform(m_pCurl));
|
|
}
|
|
catch (const Exception &e)
|
|
{
|
|
if (CURLE_COULDNT_CONNECT == e.m_errorCode)
|
|
Disconnect();
|
|
|
|
curl_easy_setopt(m_pCurl, CURLOPT_QUOTE, 0);
|
|
curl_slist_free_all(list);
|
|
return StatusCodeHelper(STATUS_CODE_FAILURE, curl_easy_strerror(static_cast<CURLcode>(e.m_errorCode)));
|
|
}
|
|
|
|
curl_easy_setopt(m_pCurl, CURLOPT_QUOTE, 0);
|
|
curl_slist_free_all(list);
|
|
|
|
return StatusCodeHelper(STATUS_CODE_SUCCESS);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCodeHelper CurlFtpHelper::DeleteFile(const FileInfoList &fileInfoList, const String &remoteDirectory)
|
|
{
|
|
if (!IsConnected())
|
|
return StatusCodeHelper(STATUS_CODE_NOT_CONNECTED);
|
|
|
|
struct curl_slist *list = 0;
|
|
|
|
try
|
|
{
|
|
for (FileInfoList::const_iterator it = fileInfoList.begin(), itEnd = fileInfoList.end(); it != itEnd; ++it)
|
|
{
|
|
String ftpCommand;
|
|
|
|
if (m_isSftp)
|
|
ftpCommand = "rm /" + remoteDirectory + "/" + it->m_name;
|
|
else
|
|
ftpCommand = "DELE " + it->m_name;
|
|
|
|
list = curl_slist_append(list, ftpCommand.c_str());
|
|
}
|
|
|
|
const String url = (remoteDirectory.empty() ? GetUrl() : GetUrl(remoteDirectory + "/"));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_URL, url.c_str()));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_NOBODY, 1));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_QUOTE, list));
|
|
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_perform(m_pCurl));
|
|
}
|
|
catch (const Exception &e)
|
|
{
|
|
if (CURLE_COULDNT_CONNECT == e.m_errorCode)
|
|
Disconnect();
|
|
|
|
curl_easy_setopt(m_pCurl, CURLOPT_QUOTE, 0);
|
|
curl_slist_free_all(list);
|
|
return StatusCodeHelper(STATUS_CODE_FAILURE, curl_easy_strerror(static_cast<CURLcode>(e.m_errorCode)));
|
|
}
|
|
|
|
curl_easy_setopt(m_pCurl, CURLOPT_QUOTE, 0);
|
|
curl_slist_free_all(list);
|
|
|
|
return StatusCodeHelper(STATUS_CODE_SUCCESS);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCodeHelper CurlFtpHelper::GetAndDeleteFile(const String &remoteFilename, const String &localFilename, const String &remoteDirectory)
|
|
{
|
|
if (!IsConnected())
|
|
return StatusCodeHelper(STATUS_CODE_NOT_CONNECTED);
|
|
|
|
struct curl_slist *list = 0;
|
|
GetFileCallbackData getFileCallbackData(localFilename, m_maxTransferRate);
|
|
|
|
try
|
|
{
|
|
String ftpCommand;
|
|
|
|
if (m_isSftp)
|
|
ftpCommand = "rm /" + remoteDirectory + "/" + remoteFilename;
|
|
else
|
|
ftpCommand = "DELE " + remoteFilename;
|
|
|
|
list = curl_slist_append(list, ftpCommand.c_str());
|
|
|
|
const String url = (remoteDirectory.empty() ? GetUrl(remoteFilename) : GetUrl(remoteDirectory + "/" + remoteFilename));
|
|
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_URL, url.c_str()));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_NOBODY, 0));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_WRITEDATA, &getFileCallbackData));
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_setopt(m_pCurl, CURLOPT_POSTQUOTE, list));
|
|
|
|
ACTIV_THROW_RESULT_IF(CURLE_OK, !=, curl_easy_perform(m_pCurl));
|
|
}
|
|
catch (const Exception &e)
|
|
{
|
|
if (CURLE_COULDNT_CONNECT == e.m_errorCode)
|
|
Disconnect();
|
|
|
|
curl_easy_setopt(m_pCurl, CURLOPT_POSTQUOTE, 0);
|
|
curl_slist_free_all(list);
|
|
|
|
return StatusCodeHelper(STATUS_CODE_FAILURE, curl_easy_strerror(static_cast<CURLcode>(e.m_errorCode)));
|
|
}
|
|
|
|
curl_easy_setopt(m_pCurl, CURLOPT_POSTQUOTE, 0);
|
|
curl_slist_free_all(list);
|
|
|
|
return StatusCodeHelper(STATUS_CODE_SUCCESS);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline size_t CurlFtpHelper::CallbackFunction(void *ptr, size_t size, size_t nmemb, void *stream)
|
|
{
|
|
size_t realsize = size * nmemb;
|
|
CallbackData *pCallBackData = static_cast<CallbackData *>(stream);
|
|
|
|
return pCallBackData->AppendData(ptr, realsize);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline CurlFtpHelper::CallbackData::CallbackData(const size_t rateLimit) :
|
|
m_messageRateThrottler(rateLimit, 100, false),
|
|
m_totalBytes(0),
|
|
m_lastSuspendByteCount(0)
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline CurlFtpHelper::CallbackData::~CallbackData()
|
|
{
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline size_t CurlFtpHelper::CallbackData::AppendData(void *ptr, size_t size)
|
|
{
|
|
return size;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void CurlFtpHelper::CallbackData::Throttle(const size_t size)
|
|
{
|
|
m_totalBytes += size;
|
|
|
|
// Throttle on kB rather than bytes.
|
|
while (((m_totalBytes - m_lastSuspendByteCount) / 1024) > 0)
|
|
{
|
|
m_lastSuspendByteCount += 1024;
|
|
m_messageRateThrottler.Suspend();
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline StatusCodeHelper CurlFtpHelper::FileListCallbackData::GetFileList(FileInfoList &fileInfoList, bool includeDirectories)
|
|
{
|
|
size_t start = 0, end = 0;
|
|
struct ftpparse parseInfo;
|
|
|
|
String &data = m_data;
|
|
|
|
// Although the standard FTP behaviour is for line endings to be "\r\n" cUrl replaces
|
|
// this during directory listing with "\n" on non windows platforms hence the code below.
|
|
// Search the cUrl source for CURL_DO_LINEEND_CONV for more details.
|
|
const String &lineEnding = File::GetEndOfLine();
|
|
const size_t lineEndingLength = lineEnding.length();
|
|
|
|
while((end = data.find(lineEnding, start)) != data.npos)
|
|
{
|
|
if (ftpparse(&parseInfo, const_cast<char*>(data.c_str()) + start, static_cast<int>(end - start)))
|
|
{
|
|
FileInfo fileInfo;
|
|
|
|
if (!(includeDirectories || !parseInfo.flagtrycwd))
|
|
{
|
|
start = end + lineEndingLength;
|
|
continue;
|
|
}
|
|
|
|
fileInfo.m_name = String(parseInfo.name, parseInfo.namelen);
|
|
|
|
if (parseInfo.size < 0)
|
|
return StatusCodeHelper(STATUS_CODE_INVALID_FORMAT);
|
|
|
|
fileInfo.m_size = static_cast<uint64_t>(parseInfo.size);
|
|
|
|
if (FTPPARSE_MTIME_UNKNOWN != parseInfo.mtimetype)
|
|
{
|
|
struct tm tm;
|
|
|
|
localtime_r(&parseInfo.mtime, &tm);
|
|
|
|
fileInfo.m_fileTime = DateTime(tm);
|
|
}
|
|
|
|
fileInfoList.push_back(fileInfo);
|
|
}
|
|
|
|
start = end + lineEndingLength;
|
|
}
|
|
|
|
return StatusCodeHelper(STATUS_CODE_SUCCESS);
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline size_t CurlFtpHelper::FileListCallbackData::AppendData(void *ptr, size_t size)
|
|
{
|
|
m_data.append(static_cast<char *>(ptr), size);
|
|
|
|
return size;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline CurlFtpHelper::GetFileCallbackData::GetFileCallbackData(const String &filename, const size_t rateLimit) :
|
|
CallbackData(rateLimit)
|
|
{
|
|
StatusCode statusCode = m_file.Create(filename, File::AccessFlags::Write(), File::ShareFlags::Read());
|
|
|
|
if (STATUS_CODE_SUCCESS != statusCode)
|
|
{
|
|
LogMessage(LOG_TYPE_ERROR, "Failed to create temp file " + filename);
|
|
ACTIV_THROW(OsException, statusCode);
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline size_t CurlFtpHelper::GetFileCallbackData::AppendData(void *ptr, size_t size)
|
|
{
|
|
try
|
|
{
|
|
uint64_t fileSize = 0;
|
|
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_file.GetSize(fileSize));
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_file.SetPosition(static_cast<int64_t>(fileSize)));
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_file.Write(ptr, size));
|
|
Throttle(size);
|
|
}
|
|
catch (const Exception &e)
|
|
{
|
|
LogMessage(LOG_TYPE_ERROR, Fmt::Format("Failed to write data to file - {}", e));
|
|
return 0;
|
|
}
|
|
|
|
return size;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline CurlFtpHelper::PutFileCallbackData::PutFileCallbackData(const String &filename, const size_t rateLimit) :
|
|
CallbackData(rateLimit)
|
|
{
|
|
StatusCode statusCode = m_file.Open(filename, File::AccessFlags::Read(), File::ShareFlags::Read());
|
|
|
|
if (STATUS_CODE_SUCCESS != statusCode)
|
|
{
|
|
LogMessage(LOG_TYPE_ERROR, "Failed to open source file " + filename);
|
|
ACTIV_THROW(OsException, statusCode);
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline size_t CurlFtpHelper::PutFileCallbackData::AppendData(void *ptr, size_t size)
|
|
{
|
|
size_t sizeRead = 0;
|
|
|
|
try
|
|
{
|
|
ACTIV_THROW_RESULT_IF(STATUS_CODE_SUCCESS, !=, m_file.Read(static_cast<byte_t *>(ptr), size, sizeRead));
|
|
Throttle(sizeRead);
|
|
}
|
|
catch (const Exception &e)
|
|
{
|
|
LogMessage(LOG_TYPE_ERROR, Fmt::Format("Failed to read data from file - {}", e));
|
|
return 0;
|
|
}
|
|
|
|
return sizeRead;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void CurlFtpHelper::SetTimeout(const uint32_t timeout)
|
|
{
|
|
m_timeout = timeout;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void CurlFtpHelper::SetLowSpeedLimit(const uint32_t lowSpeedLimit)
|
|
{
|
|
m_lowSpeedLimit = lowSpeedLimit;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void CurlFtpHelper::SetLowSpeedTime(const uint32_t lowSpeedTime)
|
|
{
|
|
m_lowSpeedTime = lowSpeedTime;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void CurlFtpHelper::SetEpsv(const bool isEpsv)
|
|
{
|
|
m_isEpsv = isEpsv;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void CurlFtpHelper::SetPort(const bool isPort)
|
|
{
|
|
m_isPort = isPort;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void CurlFtpHelper::SetEprt(const bool isEprt)
|
|
{
|
|
m_isEprt = isEprt;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void CurlFtpHelper::SetCurlLogFilename(const String &logFilename)
|
|
{
|
|
if ("" != logFilename)
|
|
{
|
|
if (m_pCurlLogFileHandle)
|
|
fclose(m_pCurlLogFileHandle);
|
|
|
|
m_pCurlLogFileHandle = fopen(logFilename.c_str(), "a+");
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void CurlFtpHelper::SetConnectTimeout(const uint32_t connectTimeout)
|
|
{
|
|
m_connectTimeout = connectTimeout;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void CurlFtpHelper::SetSftp(const bool isSftp)
|
|
{
|
|
m_isSftp = isSftp;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline void CurlFtpHelper::SetMaxTransferRate(const size_t &rate)
|
|
{
|
|
m_maxTransferRate = rate;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline uint32_t CurlFtpHelper::GetTimeout() const
|
|
{
|
|
return m_timeout;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline uint32_t CurlFtpHelper::GetLowSpeedLimit() const
|
|
{
|
|
return m_lowSpeedLimit;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline uint32_t CurlFtpHelper::GetLowSpeedTime() const
|
|
{
|
|
return m_lowSpeedTime;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline bool CurlFtpHelper::GetUseEpsv() const
|
|
{
|
|
return m_isEpsv;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline uint32_t CurlFtpHelper::GetConnectTimeout() const
|
|
{
|
|
return m_connectTimeout;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline bool CurlFtpHelper::GetIsSftp() const
|
|
{
|
|
return m_isSftp;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
inline size_t CurlFtpHelper::GetMaxTransferRate() const
|
|
{
|
|
return m_maxTransferRate;
|
|
}
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_MISC_CURL_FTP_HELPER_H)
|