From d0ad7033c3e11549529b44990ef022a655877601 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 12 May 2015 00:21:22 +0900 Subject: sftp: basic download works This commits implements basic downloading feature for sftp URI. This includes segmented downloads, and connection (sftp session) pooling. Download via HTTP proxy has not been implemented yet. --- src/SftpDownloadCommand.cc | 99 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/SftpDownloadCommand.cc (limited to 'src/SftpDownloadCommand.cc') diff --git a/src/SftpDownloadCommand.cc b/src/SftpDownloadCommand.cc new file mode 100644 index 00000000..84bfa913 --- /dev/null +++ b/src/SftpDownloadCommand.cc @@ -0,0 +1,99 @@ +/* */ +#include "SftpDownloadCommand.h" +#include "Request.h" +#include "SocketCore.h" +#include "Segment.h" +#include "DownloadEngine.h" +#include "RequestGroup.h" +#include "Option.h" +#include "FileEntry.h" +#include "SocketRecvBuffer.h" +#include "AuthConfig.h" +#include "SftpFinishDownloadCommand.h" + +namespace aria2 { + +SftpDownloadCommand::SftpDownloadCommand +(cuid_t cuid, + const std::shared_ptr& req, + const std::shared_ptr& fileEntry, + RequestGroup* requestGroup, + DownloadEngine* e, + const std::shared_ptr& socket, + std::unique_ptr authConfig) + : DownloadCommand(cuid, req, fileEntry, requestGroup, e, socket, + std::make_shared(socket)), + authConfig_(std::move(authConfig)) +{ + setWriteCheckSocket(getSocket()); +} + +SftpDownloadCommand::~SftpDownloadCommand() {} + +bool SftpDownloadCommand::prepareForNextSegment() +{ + if(getOption()->getAsBool(PREF_FTP_REUSE_CONNECTION) && + getFileEntry()->gtoloff(getSegments().front()->getPositionToWrite()) == + getFileEntry()->getLength()) { + + auto c = make_unique + (getCuid(), getRequest(), getFileEntry(), getRequestGroup(), + getDownloadEngine(), getSocket()); + + c->setStatus(Command::STATUS_ONESHOT_REALTIME); + getDownloadEngine()->setNoWait(true); + getDownloadEngine()->addCommand(std::move(c)); + + if(getRequestGroup()->downloadFinished()) { + // To run checksum checking, we had to call following function here. + DownloadCommand::prepareForNextSegment(); + } + return true; + } + + return DownloadCommand::prepareForNextSegment(); +} + +int64_t SftpDownloadCommand::getRequestEndOffset() const +{ + return getFileEntry()->getLength(); +} + +bool SftpDownloadCommand::shouldEnableWriteCheck() { + return getSocket()->wantWrite() || !getSocket()->wantRead(); +} + +} // namespace aria2 -- cgit