FtpNegotiationCommand.cc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - The high speed download utility
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * In addition, as a special exception, the copyright holders give
  22. * permission to link the code of portions of this program with the
  23. * OpenSSL library under certain conditions as described in each
  24. * individual source file, and distribute linked combinations
  25. * including the two.
  26. * You must obey the GNU General Public License in all respects
  27. * for all of the code used other than OpenSSL. If you modify
  28. * file(s) with this exception, you may extend this exception to your
  29. * version of the file(s), but you are not obligated to do so. If you
  30. * do not wish to do so, delete this exception statement from your
  31. * version. If you delete this exception statement from all source
  32. * files in the program, then also delete it here.
  33. */
  34. /* copyright --> */
  35. #include "FtpNegotiationCommand.h"
  36. #include <stdint.h>
  37. #include <cassert>
  38. #include <utility>
  39. #include <map>
  40. #include "Request.h"
  41. #include "DownloadEngine.h"
  42. #include "FtpConnection.h"
  43. #include "RequestGroup.h"
  44. #include "PieceStorage.h"
  45. #include "FtpDownloadCommand.h"
  46. #include "FileEntry.h"
  47. #include "DlAbortEx.h"
  48. #include "message.h"
  49. #include "prefs.h"
  50. #include "util.h"
  51. #include "Option.h"
  52. #include "Logger.h"
  53. #include "Segment.h"
  54. #include "DownloadContext.h"
  55. #include "DefaultBtProgressInfoFile.h"
  56. #include "RequestGroupMan.h"
  57. #include "DownloadFailureException.h"
  58. #include "Socket.h"
  59. #include "StringFormat.h"
  60. #include "DiskAdaptor.h"
  61. #include "SegmentMan.h"
  62. #include "AuthConfigFactory.h"
  63. #include "AuthConfig.h"
  64. #include "a2functional.h"
  65. #include "URISelector.h"
  66. namespace aria2 {
  67. FtpNegotiationCommand::FtpNegotiationCommand
  68. (int32_t cuid,
  69. const RequestHandle& req,
  70. const SharedHandle<FileEntry>& fileEntry,
  71. RequestGroup* requestGroup,
  72. DownloadEngine* e,
  73. const SocketHandle& s,
  74. Seq seq,
  75. const std::string& baseWorkingDir):
  76. AbstractCommand(cuid, req, fileEntry, requestGroup, e, s), sequence(seq),
  77. ftp(new FtpConnection(cuid, socket, req,
  78. e->getAuthConfigFactory()->createAuthConfig
  79. (req, requestGroup->getOption().get()),
  80. getOption().get()))
  81. {
  82. ftp->setBaseWorkingDir(baseWorkingDir);
  83. if(seq == SEQ_RECV_GREETING) {
  84. setTimeout(getOption()->getAsInt(PREF_CONNECT_TIMEOUT));
  85. }
  86. disableReadCheckSocket();
  87. setWriteCheckSocket(socket);
  88. }
  89. FtpNegotiationCommand::~FtpNegotiationCommand() {}
  90. bool FtpNegotiationCommand::executeInternal() {
  91. while(processSequence(_segments.front()));
  92. if(sequence == SEQ_RETRY) {
  93. return prepareForRetry(0);
  94. } else if(sequence == SEQ_NEGOTIATION_COMPLETED) {
  95. FtpDownloadCommand* command =
  96. new FtpDownloadCommand
  97. (cuid, req, _fileEntry, _requestGroup, ftp, e, dataSocket, socket);
  98. command->setStartupIdleTime(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME));
  99. command->setLowestDownloadSpeedLimit(getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT));
  100. if(!_fileEntry->isSingleHostMultiConnectionEnabled()) {
  101. _fileEntry->removeURIWhoseHostnameIs(req->getHost());
  102. }
  103. _requestGroup->getURISelector()->tuneDownloadCommand
  104. (_fileEntry->getRemainingUris(), command);
  105. e->commands.push_back(command);
  106. return true;
  107. } else if(sequence == SEQ_HEAD_OK || sequence == SEQ_DOWNLOAD_ALREADY_COMPLETED) {
  108. return true;
  109. } else if(sequence == SEQ_FILE_PREPARATION) {
  110. if(getOption()->getAsBool(PREF_FTP_PASV)) {
  111. sequence = SEQ_SEND_PASV;
  112. } else {
  113. sequence = SEQ_PREPARE_SERVER_SOCKET;
  114. }
  115. return false;
  116. } else if(sequence == SEQ_EXIT) {
  117. return true;
  118. } else {
  119. e->commands.push_back(this);
  120. return false;
  121. }
  122. }
  123. bool FtpNegotiationCommand::recvGreeting() {
  124. if(!checkIfConnectionEstablished
  125. (socket, _connectedHostname, _connectedAddr, _connectedPort)) {
  126. sequence = SEQ_EXIT;
  127. return false;
  128. }
  129. setTimeout(_requestGroup->getTimeout());
  130. //socket->setBlockingMode();
  131. disableWriteCheckSocket();
  132. setReadCheckSocket(socket);
  133. unsigned int status = ftp->receiveResponse();
  134. if(status == 0) {
  135. return false;
  136. }
  137. if(status != 220) {
  138. throw DL_ABORT_EX(EX_CONNECTION_FAILED);
  139. }
  140. sequence = SEQ_SEND_USER;
  141. return true;
  142. }
  143. bool FtpNegotiationCommand::sendUser() {
  144. if(ftp->sendUser()) {
  145. disableWriteCheckSocket();
  146. sequence = SEQ_RECV_USER;
  147. } else {
  148. setWriteCheckSocket(socket);
  149. }
  150. return false;
  151. }
  152. bool FtpNegotiationCommand::recvUser() {
  153. unsigned int status = ftp->receiveResponse();
  154. switch(status) {
  155. case 0:
  156. return false;
  157. case 230:
  158. sequence = SEQ_SEND_TYPE;
  159. break;
  160. case 331:
  161. sequence = SEQ_SEND_PASS;
  162. break;
  163. default:
  164. throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
  165. }
  166. return true;
  167. }
  168. bool FtpNegotiationCommand::sendPass() {
  169. if(ftp->sendPass()) {
  170. disableWriteCheckSocket();
  171. sequence = SEQ_RECV_PASS;
  172. } else {
  173. setWriteCheckSocket(socket);
  174. }
  175. return false;
  176. }
  177. bool FtpNegotiationCommand::recvPass() {
  178. unsigned int status = ftp->receiveResponse();
  179. if(status == 0) {
  180. return false;
  181. }
  182. if(status != 230) {
  183. throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
  184. }
  185. sequence = SEQ_SEND_TYPE;
  186. return true;
  187. }
  188. bool FtpNegotiationCommand::sendType() {
  189. if(ftp->sendType()) {
  190. disableWriteCheckSocket();
  191. sequence = SEQ_RECV_TYPE;
  192. } else {
  193. setWriteCheckSocket(socket);
  194. }
  195. return false;
  196. }
  197. bool FtpNegotiationCommand::recvType() {
  198. unsigned int status = ftp->receiveResponse();
  199. if(status == 0) {
  200. return false;
  201. }
  202. if(status != 200) {
  203. throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
  204. }
  205. sequence = SEQ_SEND_PWD;
  206. return true;
  207. }
  208. bool FtpNegotiationCommand::sendPwd()
  209. {
  210. if(ftp->sendPwd()) {
  211. disableWriteCheckSocket();
  212. sequence = SEQ_RECV_PWD;
  213. } else {
  214. setWriteCheckSocket(socket);
  215. }
  216. return false;
  217. }
  218. bool FtpNegotiationCommand::recvPwd()
  219. {
  220. std::string pwd;
  221. unsigned int status = ftp->receivePwdResponse(pwd);
  222. if(status == 0) {
  223. return false;
  224. }
  225. if(status != 257) {
  226. throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
  227. }
  228. ftp->setBaseWorkingDir(pwd);
  229. logger->info("CUID#%d - base working directory is '%s'", cuid, pwd.c_str());
  230. sequence = SEQ_SEND_CWD;
  231. return true;
  232. }
  233. bool FtpNegotiationCommand::sendCwd() {
  234. // Calling setReadCheckSocket() is needed when the socket is reused,
  235. setReadCheckSocket(socket);
  236. if(ftp->sendCwd()) {
  237. disableWriteCheckSocket();
  238. sequence = SEQ_RECV_CWD;
  239. } else {
  240. setWriteCheckSocket(socket);
  241. }
  242. return false;
  243. }
  244. bool FtpNegotiationCommand::recvCwd() {
  245. unsigned int status = ftp->receiveResponse();
  246. if(status == 0) {
  247. return false;
  248. }
  249. if(status != 250) {
  250. poolConnection();
  251. _requestGroup->increaseAndValidateFileNotFoundCount();
  252. if (status == 550)
  253. throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND,
  254. downloadresultcode::RESOURCE_NOT_FOUND);
  255. else
  256. throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
  257. }
  258. if(getOption()->getAsBool(PREF_REMOTE_TIME)) {
  259. sequence = SEQ_SEND_MDTM;
  260. } else {
  261. sequence = SEQ_SEND_SIZE;
  262. }
  263. return true;
  264. }
  265. bool FtpNegotiationCommand::sendMdtm()
  266. {
  267. if(ftp->sendMdtm()) {
  268. disableWriteCheckSocket();
  269. sequence = SEQ_RECV_MDTM;
  270. } else {
  271. setWriteCheckSocket(socket);
  272. }
  273. return false;
  274. }
  275. bool FtpNegotiationCommand::recvMdtm()
  276. {
  277. Time lastModifiedTime = Time::null();
  278. unsigned int status = ftp->receiveMdtmResponse(lastModifiedTime);
  279. if(status == 0) {
  280. return false;
  281. }
  282. if(status == 213) {
  283. if(lastModifiedTime.good()) {
  284. _requestGroup->updateLastModifiedTime(lastModifiedTime);
  285. time_t t = lastModifiedTime.getTime();
  286. struct tm* tms = gmtime(&t); // returned struct is statically allocated.
  287. if(tms) {
  288. logger->debug("MDTM result was parsed as: %s GMT", asctime(tms));
  289. } else {
  290. logger->debug("gmtime() failed for MDTM result.");
  291. }
  292. } else {
  293. logger->debug("MDTM response was returned, but it seems not to be a time"
  294. " value as in specified in RFC3659.");
  295. }
  296. } else {
  297. logger->info("CUID#%d - MDTM command failed.", cuid);
  298. }
  299. sequence = SEQ_SEND_SIZE;
  300. return true;
  301. }
  302. bool FtpNegotiationCommand::sendSize() {
  303. if(ftp->sendSize()) {
  304. disableWriteCheckSocket();
  305. sequence = SEQ_RECV_SIZE;
  306. } else {
  307. setWriteCheckSocket(socket);
  308. }
  309. return false;
  310. }
  311. bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
  312. {
  313. _fileEntry->setLength(totalLength);
  314. if(_fileEntry->getPath().empty()) {
  315. _fileEntry->setPath
  316. (util::applyDir
  317. (getDownloadContext()->getDir(), util::urldecode(req->getFile())));
  318. }
  319. _requestGroup->preDownloadProcessing();
  320. if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) {
  321. throw DOWNLOAD_FAILURE_EXCEPTION
  322. (StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
  323. _requestGroup->getFirstFilePath().c_str()).str());
  324. }
  325. if(totalLength == 0) {
  326. if(getOption()->getAsBool(PREF_FTP_PASV)) {
  327. sequence = SEQ_SEND_PASV;
  328. } else {
  329. sequence = SEQ_PREPARE_SERVER_SOCKET;
  330. }
  331. if(getOption()->getAsBool(PREF_DRY_RUN)) {
  332. _requestGroup->initPieceStorage();
  333. onDryRunFileFound();
  334. return false;
  335. }
  336. if(_requestGroup->downloadFinishedByFileLength()) {
  337. _requestGroup->initPieceStorage();
  338. _requestGroup->getPieceStorage()->markAllPiecesDone();
  339. sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
  340. logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
  341. _requestGroup->getGID(),
  342. _requestGroup->getFirstFilePath().c_str());
  343. poolConnection();
  344. return false;
  345. }
  346. _requestGroup->shouldCancelDownloadForSafety();
  347. _requestGroup->initPieceStorage();
  348. _requestGroup->getPieceStorage()->getDiskAdaptor()->initAndOpenFile();
  349. if(getDownloadContext()->knowsTotalLength()) {
  350. sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
  351. poolConnection();
  352. return false;
  353. }
  354. return true;
  355. } else {
  356. _requestGroup->adjustFilename
  357. (SharedHandle<BtProgressInfoFile>(new DefaultBtProgressInfoFile
  358. (_requestGroup->getDownloadContext(),
  359. SharedHandle<PieceStorage>(),
  360. getOption().get())));
  361. _requestGroup->initPieceStorage();
  362. if(getOption()->getAsBool(PREF_DRY_RUN)) {
  363. onDryRunFileFound();
  364. return false;
  365. }
  366. BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), getOption().get()));
  367. if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) {
  368. _requestGroup->getPieceStorage()->markAllPiecesDone();
  369. sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
  370. logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
  371. _requestGroup->getGID(),
  372. _requestGroup->getFirstFilePath().c_str());
  373. poolConnection();
  374. return false;
  375. }
  376. _requestGroup->loadAndOpenFile(infoFile);
  377. prepareForNextAction(this);
  378. disableReadCheckSocket();
  379. }
  380. return false;
  381. }
  382. bool FtpNegotiationCommand::recvSize() {
  383. uint64_t size = 0;
  384. unsigned int status = ftp->receiveSizeResponse(size);
  385. if(status == 0) {
  386. return false;
  387. }
  388. if(status == 213) {
  389. if(size > INT64_MAX) {
  390. throw DL_ABORT_EX
  391. (StringFormat(EX_TOO_LARGE_FILE, util::uitos(size, true).c_str()).str());
  392. }
  393. if(_requestGroup->getPieceStorage().isNull()) {
  394. sequence = SEQ_FILE_PREPARATION;
  395. return onFileSizeDetermined(size);
  396. } else {
  397. _requestGroup->validateTotalLength(_fileEntry->getLength(), size);
  398. }
  399. } else {
  400. logger->info("CUID#%d - The remote FTP Server doesn't recognize SIZE command. Continue.", cuid);
  401. // Even if one of the other servers waiting in the queue supports SIZE
  402. // command, resuming and segmented downloading are disabled when the first
  403. // contacted FTP server doesn't support it.
  404. if(_requestGroup->getPieceStorage().isNull()) {
  405. getDownloadContext()->markTotalLengthIsUnknown();
  406. return onFileSizeDetermined(0);
  407. }
  408. // TODO Skipping RequestGroup::validateTotalLength(0) here will allow
  409. // wrong file to be downloaded if user-specified URL is wrong.
  410. }
  411. if(getOption()->getAsBool(PREF_FTP_PASV)) {
  412. sequence = SEQ_SEND_PASV;
  413. } else {
  414. sequence = SEQ_PREPARE_SERVER_SOCKET;
  415. }
  416. return true;
  417. }
  418. void FtpNegotiationCommand::afterFileAllocation()
  419. {
  420. setReadCheckSocket(socket);
  421. }
  422. bool FtpNegotiationCommand::prepareServerSocket()
  423. {
  424. serverSocket = ftp->createServerSocket();
  425. sequence = SEQ_SEND_PORT;
  426. return true;
  427. }
  428. bool FtpNegotiationCommand::sendPort() {
  429. afterFileAllocation();
  430. if(ftp->sendPort(serverSocket)) {
  431. disableWriteCheckSocket();
  432. sequence = SEQ_RECV_PORT;
  433. } else {
  434. setWriteCheckSocket(socket);
  435. }
  436. return false;
  437. }
  438. bool FtpNegotiationCommand::recvPort() {
  439. unsigned int status = ftp->receiveResponse();
  440. if(status == 0) {
  441. return false;
  442. }
  443. if(status != 200) {
  444. throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
  445. }
  446. sequence = SEQ_SEND_REST;
  447. return true;
  448. }
  449. bool FtpNegotiationCommand::sendPasv() {
  450. afterFileAllocation();
  451. if(ftp->sendPasv()) {
  452. disableWriteCheckSocket();
  453. sequence = SEQ_RECV_PASV;
  454. } else {
  455. setWriteCheckSocket(socket);
  456. }
  457. return false;
  458. }
  459. bool FtpNegotiationCommand::recvPasv() {
  460. std::pair<std::string, uint16_t> dest;
  461. unsigned int status = ftp->receivePasvResponse(dest);
  462. if(status == 0) {
  463. return false;
  464. }
  465. if(status != 227) {
  466. throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
  467. }
  468. // make a data connection to the server.
  469. logger->info(MSG_CONNECTING_TO_SERVER, cuid,
  470. dest.first.c_str(),
  471. dest.second);
  472. dataSocket.reset(new SocketCore());
  473. dataSocket->establishConnection(dest.first, dest.second);
  474. disableReadCheckSocket();
  475. setWriteCheckSocket(dataSocket);
  476. sequence = SEQ_SEND_REST_PASV;
  477. return false;
  478. }
  479. bool FtpNegotiationCommand::sendRestPasv(const SegmentHandle& segment) {
  480. //dataSocket->setBlockingMode();
  481. setReadCheckSocket(socket);
  482. disableWriteCheckSocket();
  483. return sendRest(segment);
  484. }
  485. bool FtpNegotiationCommand::sendRest(const SegmentHandle& segment) {
  486. if(ftp->sendRest(segment)) {
  487. disableWriteCheckSocket();
  488. sequence = SEQ_RECV_REST;
  489. } else {
  490. setWriteCheckSocket(socket);
  491. }
  492. return false;
  493. }
  494. bool FtpNegotiationCommand::recvRest(const SharedHandle<Segment>& segment) {
  495. unsigned int status = ftp->receiveResponse();
  496. if(status == 0) {
  497. return false;
  498. }
  499. // If we recieve negative response and requested file position is not 0,
  500. // then throw exception here.
  501. if(status != 350) {
  502. if(!segment.isNull() && segment->getPositionToWrite() != 0) {
  503. throw DL_ABORT_EX("FTP server doesn't support resuming.");
  504. }
  505. }
  506. sequence = SEQ_SEND_RETR;
  507. return true;
  508. }
  509. bool FtpNegotiationCommand::sendRetr() {
  510. if(ftp->sendRetr()) {
  511. disableWriteCheckSocket();
  512. sequence = SEQ_RECV_RETR;
  513. } else {
  514. setWriteCheckSocket(socket);
  515. }
  516. return false;
  517. }
  518. bool FtpNegotiationCommand::recvRetr() {
  519. unsigned int status = ftp->receiveResponse();
  520. if(status == 0) {
  521. return false;
  522. }
  523. if(status != 150 && status != 125) {
  524. _requestGroup->increaseAndValidateFileNotFoundCount();
  525. if (status == 550)
  526. throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND,
  527. downloadresultcode::RESOURCE_NOT_FOUND);
  528. else
  529. throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
  530. }
  531. if(getOption()->getAsBool(PREF_FTP_PASV)) {
  532. sequence = SEQ_NEGOTIATION_COMPLETED;
  533. return false;
  534. } else {
  535. disableReadCheckSocket();
  536. setReadCheckSocket(serverSocket);
  537. sequence = SEQ_WAIT_CONNECTION;
  538. return false;
  539. }
  540. }
  541. bool FtpNegotiationCommand::waitConnection()
  542. {
  543. disableReadCheckSocket();
  544. setReadCheckSocket(socket);
  545. dataSocket.reset(serverSocket->acceptConnection());
  546. dataSocket->setNonBlockingMode();
  547. sequence = SEQ_NEGOTIATION_COMPLETED;
  548. return false;
  549. }
  550. bool FtpNegotiationCommand::processSequence(const SegmentHandle& segment) {
  551. bool doNextSequence = true;
  552. switch(sequence) {
  553. case SEQ_RECV_GREETING:
  554. return recvGreeting();
  555. case SEQ_SEND_USER:
  556. return sendUser();
  557. case SEQ_RECV_USER:
  558. return recvUser();
  559. case SEQ_SEND_PASS:
  560. return sendPass();
  561. case SEQ_RECV_PASS:
  562. return recvPass();
  563. case SEQ_SEND_TYPE:
  564. return sendType();
  565. case SEQ_RECV_TYPE:
  566. return recvType();
  567. case SEQ_SEND_PWD:
  568. return sendPwd();
  569. case SEQ_RECV_PWD:
  570. return recvPwd();
  571. case SEQ_SEND_CWD:
  572. return sendCwd();
  573. case SEQ_RECV_CWD:
  574. return recvCwd();
  575. case SEQ_SEND_MDTM:
  576. return sendMdtm();
  577. case SEQ_RECV_MDTM:
  578. return recvMdtm();
  579. case SEQ_SEND_SIZE:
  580. return sendSize();
  581. case SEQ_RECV_SIZE:
  582. return recvSize();
  583. case SEQ_PREPARE_SERVER_SOCKET:
  584. return prepareServerSocket();
  585. case SEQ_SEND_PORT:
  586. return sendPort();
  587. case SEQ_RECV_PORT:
  588. return recvPort();
  589. case SEQ_SEND_PASV:
  590. return sendPasv();
  591. case SEQ_RECV_PASV:
  592. return recvPasv();
  593. case SEQ_SEND_REST_PASV:
  594. return sendRestPasv(segment);
  595. case SEQ_SEND_REST:
  596. return sendRest(segment);
  597. case SEQ_RECV_REST:
  598. return recvRest(segment);
  599. case SEQ_SEND_RETR:
  600. return sendRetr();
  601. case SEQ_RECV_RETR:
  602. return recvRetr();
  603. case SEQ_WAIT_CONNECTION:
  604. return waitConnection();
  605. default:
  606. abort();
  607. }
  608. return doNextSequence;
  609. }
  610. void FtpNegotiationCommand::poolConnection() const
  611. {
  612. if(getOption()->getAsBool(PREF_FTP_REUSE_CONNECTION)) {
  613. std::map<std::string, std::string> options;
  614. options["baseWorkingDir"] = ftp->getBaseWorkingDir();
  615. e->poolSocket(req, isProxyDefined(), socket, options);
  616. }
  617. }
  618. void FtpNegotiationCommand::onDryRunFileFound()
  619. {
  620. _requestGroup->getPieceStorage()->markAllPiecesDone();
  621. poolConnection();
  622. sequence = SEQ_HEAD_OK;
  623. }
  624. } // namespace aria2