/* */ #ifndef _D_FTP_CONNECTION_H_ #define _D_FTP_CONNECTION_H_ #include "common.h" #include #include #include "SharedHandle.h" #include "TimeA2.h" #include "SocketBuffer.h" namespace aria2 { class Option; class Logger; class Segment; class Request; class SocketCore; class AuthConfig; class FtpConnection { private: int32_t cuid; SharedHandle socket; SharedHandle req; SharedHandle _authConfig; const Option* option; Logger* logger; std::string strbuf; SocketBuffer _socketBuffer; std::string _baseWorkingDir; unsigned int getStatus(const std::string& response) const; std::string::size_type findEndOfResponse(unsigned int status, const std::string& buf) const; bool bulkReceiveResponse(std::pair& response); static const std::string A; static const std::string I; static const size_t MAX_RECV_BUFFER = 4096; public: FtpConnection(int32_t cuid, const SharedHandle& socket, const SharedHandle& req, const SharedHandle& authConfig, const Option* op); ~FtpConnection(); bool sendUser(); bool sendPass(); bool sendType(); bool sendPwd(); bool sendCwd(); bool sendMdtm(); bool sendSize(); bool sendPasv(); SharedHandle createServerSocket(); bool sendPort(const SharedHandle& serverSocket); bool sendRest(const SharedHandle& segment); bool sendRetr(); unsigned int receiveResponse(); unsigned int receiveSizeResponse(uint64_t& size); // Returns status code of MDTM reply. If the status code is 213, parses // time-val and store it in time. // If a code other than 213 is returned, time is not touched. // Expect MDTM reply is YYYYMMDDhhmmss in GMT. If status is 213 but returned // date cannot be parsed, then executes time.setTimeInSec(-1). // If reply is not received yet, returns 0. unsigned int receiveMdtmResponse(Time& time); unsigned int receivePasvResponse(std::pair& dest); unsigned int receivePwdResponse(std::string& pwd); void setBaseWorkingDir(const std::string& baseWorkingDir); const std::string& getBaseWorkingDir() const; }; } // namespace aria2 #endif // _D_FTP_CONNECTION_H_