FTPS Client
gxsFTPClient transfers files with FTPS. Control and data connections are always encrypted.
Overview
Connect() uses explicit TLS (AUTH TLS on port 21) by default or implicit TLS (port 990). Login() sends PBSZ 0 and PROT P so every data connection is encrypted, then selects binary mode. Transfers are passive: EPSV first, then PASV, and the data connection always goes to the address of the control connection, never to an address in a PASV reply. Data connections reuse the control connection's TLS session, which most FTPS servers require.
Plain FTP is not supported. For transfers over SSH (SFTP) use an SSH library.
gxsFTPClient ftp;
long long bytes = 0;
if(ftp.Connect("ftp.example.com") == 0 && ftp.Login("user", "pw") == 0)
ftp.Get("report.pdf", "report.pdf", bytes);
ftp.Quit();
Functions
int gxsFTPClient::Connect(const std::string &host, int port = gxSOCKET_FTP_PORT, gxsMailSecurity security = gxsMAIL_STARTTLS)Connects and starts TLS. Returns 0 if successful.
int gxsFTPClient::Login(const std::string &user, const std::string &passwd)Logs in and protects the data channel.
int gxsFTPClient::List(const std::string &path, std::string &listing, bool full = true)LIST (full) or NLST.
int gxsFTPClient::Get(const std::string &remote, const std::string &local_fname, long long &bytes)Downloads a file.
int gxsFTPClient::Put(const std::string &local_fname, const std::string &remote, long long &bytes)Uploads a file.
int gxsFTPClient::GetString(const std::string &remote, std::string &data) / PutString(...)Transfers to and from memory.
int gxsFTPClient::ChDir / MkDir / RmDir / PWD / Size / Delete / RenameDirectory and file commands.
int gxsFTPClient::Type(char type = 'I')Binary (I) or ASCII (A) mode.
int gxsFTPClient::Command(const std::string &cmd, const std::string &expect)Sends any command.
int gxsFTPClient::Quit()QUIT and close.