/* */ #ifndef _D_FTP_CONNECTION_H_ #define _D_FTP_CONNECTION_H_ #include "common.h" #include #include #include "SharedHandle.h" #include "TimeA2.h" #include "SocketBuffer.h" #include "Command.h" namespace aria2 { class Option; class Logger; class Segment; class Request; class SocketCore; class AuthConfig; class FtpConnection { private: cuid_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; //prepare for large banners static const size_t MAX_RECV_BUFFER = 65536; public: FtpConnection(cuid_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 assign Time::null() to given time. // 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 { return baseWorkingDir_; } const std::string& getUser() const; }; } // namespace aria2 #endif // _D_FTP_CONNECTION_H_