/* */ #include "FtpFinishDownloadCommand.h" #include "Request.h" #include "DownloadEngine.h" #include "prefs.h" #include "Option.h" #include "FtpConnection.h" #include "message.h" #include "StringFormat.h" #include "DlAbortEx.h" #include "SocketCore.h" #include "RequestGroup.h" #include "Logger.h" namespace aria2 { FtpFinishDownloadCommand::FtpFinishDownloadCommand (int cuid, const RequestHandle& req, RequestGroup* requestGroup, const SharedHandle& ftpConnection, DownloadEngine* e, const SharedHandle& socket) :AbstractCommand(cuid, req, requestGroup, e, socket), _ftpConnection(ftpConnection) { e->addSocketForReadCheck(socket, this); } FtpFinishDownloadCommand::~FtpFinishDownloadCommand() { e->deleteSocketForReadCheck(socket, this); } // overrides AbstractCommand::execute(). // AbstractCommand::_segments is empty. bool FtpFinishDownloadCommand::execute() { if(_requestGroup->isHaltRequested()) { return true; } try { unsigned int status = _ftpConnection->receiveResponse(); if(status == 0) { e->commands.push_back(this); return false; } if(status != 226) { throw DlAbortEx(StringFormat(EX_BAD_STATUS, status).str()); } if(!e->option->getAsBool(PREF_HTTP_PROXY_ENABLED) && e->option->getAsBool(PREF_FTP_REUSE_CONNECTION)) { std::pair peerInfo; socket->getPeerInfo(peerInfo); e->poolSocket(peerInfo.first, peerInfo.second, socket); } } catch(RecoverableException& e) { logger->info(EX_EXCEPTION_CAUGHT, e); } if(_requestGroup->downloadFinished()) { return true; } else { return prepareForRetry(0); } } // This function never be called. bool FtpFinishDownloadCommand::executeInternal() { return true; } } // namespace aria2