/* */ #ifndef D_FTP_CONNECTION_H #define D_FTP_CONNECTION_H #include "common.h" #include #include #include #include "TimeA2.h" #include "SocketBuffer.h" #include "Command.h" #include "a2functional.h" namespace aria2 { class Option; class Segment; class Request; class SocketCore; class AuthConfig; class FtpConnection { private: cuid_t cuid_; std::shared_ptr socket_; std::shared_ptr req_; std::shared_ptr authConfig_; const Option* option_; std::string strbuf_; SocketBuffer socketBuffer_; std::string baseWorkingDir_; int getStatus(const std::string& response) const; std::string::size_type findEndOfResponse(int status, const std::string& buf) const; bool bulkReceiveResponse(std::pair& response); // prepare for large banners static const size_t MAX_RECV_BUFFER = 64_k; public: FtpConnection(cuid_t cuid, const std::shared_ptr& socket, const std::shared_ptr& req, const std::shared_ptr& authConfig, const Option* op); ~FtpConnection(); bool sendUser(); bool sendPass(); bool sendType(); bool sendPwd(); bool sendCwd(const std::string& dir); bool sendMdtm(); bool sendSize(); bool sendEpsv(); bool sendPasv(); std::shared_ptr createServerSocket(); bool sendEprt(const std::shared_ptr& serverSocket); bool sendPort(const std::shared_ptr& serverSocket); bool sendRest(const std::shared_ptr& segment); bool sendRetr(); int receiveResponse(); int receiveSizeResponse(int64_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 assign Time::null() to given time. // If reply is not received yet, returns 0. int receiveMdtmResponse(Time& time); int receiveEpsvResponse(uint16_t& port); int receivePasvResponse(std::pair& dest); int receivePwdResponse(std::string& pwd); void setBaseWorkingDir(const std::string& baseWorkingDir); const std::string& getBaseWorkingDir() const { return baseWorkingDir_; } const std::string& getUser() const; }; } // namespace aria2 #endif // D_FTP_CONNECTION_H