FtpNegotiationCommand.cc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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 "SingleFileDownloadContext.h"
  55. #include "DefaultBtProgressInfoFile.h"
  56. #include "RequestGroupMan.h"
  57. #include "DownloadFailureException.h"
  58. #include "ServerHost.h"
  59. #include "Socket.h"
  60. #include "StringFormat.h"
  61. #include "DiskAdaptor.h"
  62. #include "SegmentMan.h"
  63. #include "AuthConfigFactory.h"
  64. #include "AuthConfig.h"
  65. #include "a2functional.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(req),
  79. getOption().get()))
  80. {
  81. ftp->setBaseWorkingDir(baseWorkingDir);
  82. if(seq == SEQ_RECV_GREETING) {
  83. setTimeout(getOption()->getAsInt(PREF_CONNECT_TIMEOUT));
  84. }
  85. disableReadCheckSocket();
  86. setWriteCheckSocket(socket);
  87. }
  88. FtpNegotiationCommand::~FtpNegotiationCommand() {}
  89. bool FtpNegotiationCommand::executeInternal() {
  90. while(processSequence(_segments.front()));
  91. if(sequence == SEQ_RETRY) {
  92. return prepareForRetry(0);
  93. } else if(sequence == SEQ_NEGOTIATION_COMPLETED) {
  94. FtpDownloadCommand* command =
  95. new FtpDownloadCommand
  96. (cuid, req, _fileEntry, _requestGroup, ftp, e, dataSocket, socket);
  97. command->setStartupIdleTime(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME));
  98. command->setLowestDownloadSpeedLimit(getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT));
  99. if(!_requestGroup->isSingleHostMultiConnectionEnabled()) {
  100. SharedHandle<ServerHost> sv =
  101. _requestGroup->searchServerHost(req->getHost());
  102. if(!sv.isNull()) {
  103. _requestGroup->removeURIWhoseHostnameIs(sv->getHostname());
  104. }
  105. }
  106. _requestGroup->tuneDownloadCommand(command);
  107. e->commands.push_back(command);
  108. return true;
  109. } else if(sequence == SEQ_HEAD_OK || sequence == SEQ_DOWNLOAD_ALREADY_COMPLETED) {
  110. return true;
  111. } else if(sequence == SEQ_FILE_PREPARATION) {
  112. if(getOption()->getAsBool(PREF_FTP_PASV)) {
  113. sequence = SEQ_SEND_PASV;
  114. } else {
  115. sequence = SEQ_PREPARE_SERVER_SOCKET;
  116. }
  117. return false;
  118. } else {
  119. e->commands.push_back(this);
  120. return false;
  121. }
  122. }
  123. bool FtpNegotiationCommand::recvGreeting() {
  124. checkIfConnectionEstablished(socket);
  125. setTimeout(_requestGroup->getTimeout());
  126. //socket->setBlockingMode();
  127. disableWriteCheckSocket();
  128. setReadCheckSocket(socket);
  129. unsigned int status = ftp->receiveResponse();
  130. if(status == 0) {
  131. return false;
  132. }
  133. if(status != 220) {
  134. throw DL_ABORT_EX(EX_CONNECTION_FAILED);
  135. }
  136. sequence = SEQ_SEND_USER;
  137. return true;
  138. }
  139. bool FtpNegotiationCommand::sendUser() {
  140. if(ftp->sendUser()) {
  141. disableWriteCheckSocket();
  142. sequence = SEQ_RECV_USER;
  143. } else {
  144. setWriteCheckSocket(socket);
  145. }
  146. return false;
  147. }
  148. bool FtpNegotiationCommand::recvUser() {
  149. unsigned int status = ftp->receiveResponse();
  150. switch(status) {
  151. case 0:
  152. return false;
  153. case 230:
  154. sequence = SEQ_SEND_TYPE;
  155. break;
  156. case 331:
  157. sequence = SEQ_SEND_PASS;
  158. break;
  159. default:
  160. throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
  161. }
  162. return true;
  163. }
  164. bool FtpNegotiationCommand::sendPass() {
  165. if(ftp->sendPass()) {
  166. disableWriteCheckSocket();
  167. sequence = SEQ_RECV_PASS;
  168. } else {
  169. setWriteCheckSocket(socket);
  170. }
  171. return false;
  172. }
  173. bool FtpNegotiationCommand::recvPass() {
  174. unsigned int status = ftp->receiveResponse();
  175. if(status == 0) {
  176. return false;
  177. }
  178. if(status != 230) {
  179. throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
  180. }
  181. sequence = SEQ_SEND_TYPE;
  182. return true;
  183. }
  184. bool FtpNegotiationCommand::sendType() {
  185. if(ftp->sendType()) {
  186. disableWriteCheckSocket();
  187. sequence = SEQ_RECV_TYPE;
  188. } else {
  189. setWriteCheckSocket(socket);
  190. }
  191. return false;
  192. }
  193. bool FtpNegotiationCommand::recvType() {
  194. unsigned int status = ftp->receiveResponse();
  195. if(status == 0) {
  196. return false;
  197. }
  198. if(status != 200) {
  199. throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
  200. }
  201. sequence = SEQ_SEND_PWD;
  202. return true;
  203. }
  204. bool FtpNegotiationCommand::sendPwd()
  205. {
  206. if(ftp->sendPwd()) {
  207. disableWriteCheckSocket();
  208. sequence = SEQ_RECV_PWD;
  209. } else {
  210. setWriteCheckSocket(socket);
  211. }
  212. return false;
  213. }
  214. bool FtpNegotiationCommand::recvPwd()
  215. {
  216. std::string pwd;
  217. unsigned int status = ftp->receivePwdResponse(pwd);
  218. if(status == 0) {
  219. return false;
  220. }
  221. if(status != 257) {
  222. throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
  223. }
  224. ftp->setBaseWorkingDir(pwd);
  225. logger->info("CUID#%d - base working directory is '%s'", cuid, pwd.c_str());
  226. sequence = SEQ_SEND_CWD;
  227. return true;
  228. }
  229. bool FtpNegotiationCommand::sendCwd() {
  230. // Calling setReadCheckSocket() is needed when the socket is reused,
  231. setReadCheckSocket(socket);
  232. if(ftp->sendCwd()) {
  233. disableWriteCheckSocket();
  234. sequence = SEQ_RECV_CWD;
  235. } else {
  236. setWriteCheckSocket(socket);
  237. }
  238. return false;
  239. }
  240. bool FtpNegotiationCommand::recvCwd() {
  241. unsigned int status = ftp->receiveResponse();
  242. if(status == 0) {
  243. return false;
  244. }
  245. if(status != 250) {
  246. poolConnection();
  247. _requestGroup->increaseAndValidateFileNotFoundCount();
  248. if (status == 550)
  249. throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND, DownloadResult::RESOURCE_NOT_FOUND);
  250. else
  251. throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
  252. }
  253. if(getOption()->getAsBool(PREF_REMOTE_TIME)) {
  254. sequence = SEQ_SEND_MDTM;
  255. } else {
  256. sequence = SEQ_SEND_SIZE;
  257. }
  258. return true;
  259. }
  260. bool FtpNegotiationCommand::sendMdtm()
  261. {
  262. if(ftp->sendMdtm()) {
  263. disableWriteCheckSocket();
  264. sequence = SEQ_RECV_MDTM;
  265. } else {
  266. setWriteCheckSocket(socket);
  267. }
  268. return false;
  269. }
  270. bool FtpNegotiationCommand::recvMdtm()
  271. {
  272. Time lastModifiedTime = Time::null();
  273. unsigned int status = ftp->receiveMdtmResponse(lastModifiedTime);
  274. if(status == 0) {
  275. return false;
  276. }
  277. if(status == 213) {
  278. if(lastModifiedTime.good()) {
  279. _requestGroup->updateLastModifiedTime(lastModifiedTime);
  280. time_t t = lastModifiedTime.getTime();
  281. struct tm* tms = gmtime(&t); // returned struct is statically allocated.
  282. if(tms) {
  283. logger->debug("MDTM result was parsed as: %s GMT", asctime(tms));
  284. } else {
  285. logger->debug("gmtime() failed for MDTM result.");
  286. }
  287. } else {
  288. logger->debug("MDTM response was returned, but it seems not to be a time"
  289. " value as in specified in RFC3659.");
  290. }
  291. } else {
  292. logger->info("CUID#%d - MDTM command failed.", cuid);
  293. }
  294. sequence = SEQ_SEND_SIZE;
  295. return true;
  296. }
  297. bool FtpNegotiationCommand::sendSize() {
  298. if(ftp->sendSize()) {
  299. disableWriteCheckSocket();
  300. sequence = SEQ_RECV_SIZE;
  301. } else {
  302. setWriteCheckSocket(socket);
  303. }
  304. return false;
  305. }
  306. bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
  307. {
  308. SingleFileDownloadContextHandle dctx =
  309. dynamic_pointer_cast<SingleFileDownloadContext>(_requestGroup->getDownloadContext());
  310. dctx->setTotalLength(totalLength);
  311. _fileEntry->setLength(totalLength);
  312. dctx->setFilename
  313. (strconcat(dctx->getDir(), "/", Util::urldecode(req->getFile())));
  314. _requestGroup->preDownloadProcessing();
  315. if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) {
  316. throw DOWNLOAD_FAILURE_EXCEPTION
  317. (StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
  318. _requestGroup->getFilePath().c_str()).str());
  319. }
  320. if(totalLength == 0) {
  321. if(getOption()->getAsBool(PREF_FTP_PASV)) {
  322. sequence = SEQ_SEND_PASV;
  323. } else {
  324. sequence = SEQ_PREPARE_SERVER_SOCKET;
  325. }
  326. if(getOption()->getAsBool(PREF_DRY_RUN)) {
  327. _requestGroup->initPieceStorage();
  328. onDryRunFileFound();
  329. return false;
  330. }
  331. if(_requestGroup->downloadFinishedByFileLength()) {
  332. _requestGroup->initPieceStorage();
  333. _requestGroup->getPieceStorage()->markAllPiecesDone();
  334. sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
  335. logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
  336. _requestGroup->getGID(),
  337. _requestGroup->getFilePath().c_str());
  338. poolConnection();
  339. return false;
  340. }
  341. _requestGroup->shouldCancelDownloadForSafety();
  342. _requestGroup->initPieceStorage();
  343. _requestGroup->getPieceStorage()->getDiskAdaptor()->initAndOpenFile();
  344. if(dctx->knowsTotalLength()) {
  345. sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
  346. poolConnection();
  347. return false;
  348. }
  349. return true;
  350. } else {
  351. _requestGroup->adjustFilename
  352. (SharedHandle<BtProgressInfoFile>(new DefaultBtProgressInfoFile
  353. (_requestGroup->getDownloadContext(),
  354. SharedHandle<PieceStorage>(),
  355. getOption().get())));
  356. _requestGroup->initPieceStorage();
  357. if(getOption()->getAsBool(PREF_DRY_RUN)) {
  358. onDryRunFileFound();
  359. return false;
  360. }
  361. BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), getOption().get()));
  362. if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) {
  363. _requestGroup->getPieceStorage()->markAllPiecesDone();
  364. sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
  365. logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
  366. _requestGroup->getGID(),
  367. _requestGroup->getFilePath().c_str());
  368. poolConnection();
  369. return false;
  370. }
  371. _requestGroup->loadAndOpenFile(infoFile);
  372. prepareForNextAction(this);
  373. disableReadCheckSocket();
  374. }
  375. return false;
  376. }
  377. bool FtpNegotiationCommand::recvSize() {
  378. uint64_t size = 0;
  379. unsigned int status = ftp->receiveSizeResponse(size);
  380. if(status == 0) {
  381. return false;
  382. }
  383. if(status == 213) {
  384. if(size > INT64_MAX) {
  385. throw DL_ABORT_EX
  386. (StringFormat(EX_TOO_LARGE_FILE, Util::uitos(size, true).c_str()).str());
  387. }
  388. if(_requestGroup->getPieceStorage().isNull()) {
  389. sequence = SEQ_FILE_PREPARATION;
  390. return onFileSizeDetermined(size);
  391. } else {
  392. _requestGroup->validateTotalLength(_fileEntry->getLength(), size);
  393. }
  394. } else {
  395. logger->info("CUID#%d - The remote FTP Server doesn't recognize SIZE command. Continue.", cuid);
  396. // Even if one of the other servers waiting in the queue supports SIZE
  397. // command, resuming and segmented downloading are disabled when the first
  398. // contacted FTP server doesn't support it.
  399. if(_requestGroup->getPieceStorage().isNull()) {
  400. SingleFileDownloadContextHandle dctx =
  401. dynamic_pointer_cast<SingleFileDownloadContext>
  402. (_requestGroup->getDownloadContext());
  403. dctx->markTotalLengthIsUnknown();
  404. return onFileSizeDetermined(0);
  405. }
  406. // TODO Skipping RequestGroup::validateTotalLength(0) here will allow
  407. // wrong file to be downloaded if user-specified URL is wrong.
  408. }
  409. if(getOption()->getAsBool(PREF_FTP_PASV)) {
  410. sequence = SEQ_SEND_PASV;
  411. } else {
  412. sequence = SEQ_PREPARE_SERVER_SOCKET;
  413. }
  414. return true;
  415. }
  416. void FtpNegotiationCommand::afterFileAllocation()
  417. {
  418. setReadCheckSocket(socket);
  419. }
  420. bool FtpNegotiationCommand::prepareServerSocket()
  421. {
  422. serverSocket = ftp->createServerSocket();
  423. sequence = SEQ_SEND_PORT;
  424. return true;
  425. }
  426. bool FtpNegotiationCommand::sendPort() {
  427. afterFileAllocation();
  428. if(ftp->sendPort(serverSocket)) {
  429. disableWriteCheckSocket();
  430. sequence = SEQ_RECV_PORT;
  431. } else {
  432. setWriteCheckSocket(socket);
  433. }
  434. return false;
  435. }
  436. bool FtpNegotiationCommand::recvPort() {
  437. unsigned int status = ftp->receiveResponse();
  438. if(status == 0) {
  439. return false;
  440. }
  441. if(status != 200) {
  442. throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
  443. }
  444. sequence = SEQ_SEND_REST;
  445. return true;
  446. }
  447. bool FtpNegotiationCommand::sendPasv() {
  448. afterFileAllocation();
  449. if(ftp->sendPasv()) {
  450. disableWriteCheckSocket();
  451. sequence = SEQ_RECV_PASV;
  452. } else {
  453. setWriteCheckSocket(socket);
  454. }
  455. return false;
  456. }
  457. bool FtpNegotiationCommand::recvPasv() {
  458. std::pair<std::string, uint16_t> dest;
  459. unsigned int status = ftp->receivePasvResponse(dest);
  460. if(status == 0) {
  461. return false;
  462. }
  463. if(status != 227) {
  464. throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
  465. }
  466. // make a data connection to the server.
  467. logger->info(MSG_CONNECTING_TO_SERVER, cuid,
  468. dest.first.c_str(),
  469. dest.second);
  470. dataSocket.reset(new SocketCore());
  471. dataSocket->establishConnection(dest.first, dest.second);
  472. disableReadCheckSocket();
  473. setWriteCheckSocket(dataSocket);
  474. sequence = SEQ_SEND_REST_PASV;
  475. return false;
  476. }
  477. bool FtpNegotiationCommand::sendRestPasv(const SegmentHandle& segment) {
  478. //dataSocket->setBlockingMode();
  479. setReadCheckSocket(socket);
  480. disableWriteCheckSocket();
  481. return sendRest(segment);
  482. }
  483. bool FtpNegotiationCommand::sendRest(const SegmentHandle& segment) {
  484. if(ftp->sendRest(segment)) {
  485. disableWriteCheckSocket();
  486. sequence = SEQ_RECV_REST;
  487. } else {
  488. setWriteCheckSocket(socket);
  489. }
  490. return false;
  491. }
  492. bool FtpNegotiationCommand::recvRest(const SharedHandle<Segment>& segment) {
  493. unsigned int status = ftp->receiveResponse();
  494. if(status == 0) {
  495. return false;
  496. }
  497. // If we recieve negative response and requested file position is not 0,
  498. // then throw exception here.
  499. if(status != 350) {
  500. if(!segment.isNull() && segment->getPositionToWrite() != 0) {
  501. throw DL_ABORT_EX("FTP server doesn't support resuming.");
  502. }
  503. }
  504. sequence = SEQ_SEND_RETR;
  505. return true;
  506. }
  507. bool FtpNegotiationCommand::sendRetr() {
  508. if(ftp->sendRetr()) {
  509. disableWriteCheckSocket();
  510. sequence = SEQ_RECV_RETR;
  511. } else {
  512. setWriteCheckSocket(socket);
  513. }
  514. return false;
  515. }
  516. bool FtpNegotiationCommand::recvRetr() {
  517. unsigned int status = ftp->receiveResponse();
  518. if(status == 0) {
  519. return false;
  520. }
  521. if(status != 150 && status != 125) {
  522. _requestGroup->increaseAndValidateFileNotFoundCount();
  523. if (status == 550)
  524. throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND, DownloadResult::RESOURCE_NOT_FOUND);
  525. else
  526. throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
  527. }
  528. if(getOption()->getAsBool(PREF_FTP_PASV)) {
  529. sequence = SEQ_NEGOTIATION_COMPLETED;
  530. return false;
  531. } else {
  532. disableReadCheckSocket();
  533. setReadCheckSocket(serverSocket);
  534. sequence = SEQ_WAIT_CONNECTION;
  535. return false;
  536. }
  537. }
  538. bool FtpNegotiationCommand::waitConnection()
  539. {
  540. disableReadCheckSocket();
  541. setReadCheckSocket(socket);
  542. dataSocket.reset(serverSocket->acceptConnection());
  543. dataSocket->setNonBlockingMode();
  544. sequence = SEQ_NEGOTIATION_COMPLETED;
  545. return false;
  546. }
  547. bool FtpNegotiationCommand::processSequence(const SegmentHandle& segment) {
  548. bool doNextSequence = true;
  549. switch(sequence) {
  550. case SEQ_RECV_GREETING:
  551. return recvGreeting();
  552. case SEQ_SEND_USER:
  553. return sendUser();
  554. case SEQ_RECV_USER:
  555. return recvUser();
  556. case SEQ_SEND_PASS:
  557. return sendPass();
  558. case SEQ_RECV_PASS:
  559. return recvPass();
  560. case SEQ_SEND_TYPE:
  561. return sendType();
  562. case SEQ_RECV_TYPE:
  563. return recvType();
  564. case SEQ_SEND_PWD:
  565. return sendPwd();
  566. case SEQ_RECV_PWD:
  567. return recvPwd();
  568. case SEQ_SEND_CWD:
  569. return sendCwd();
  570. case SEQ_RECV_CWD:
  571. return recvCwd();
  572. case SEQ_SEND_MDTM:
  573. return sendMdtm();
  574. case SEQ_RECV_MDTM:
  575. return recvMdtm();
  576. case SEQ_SEND_SIZE:
  577. return sendSize();
  578. case SEQ_RECV_SIZE:
  579. return recvSize();
  580. case SEQ_PREPARE_SERVER_SOCKET:
  581. return prepareServerSocket();
  582. case SEQ_SEND_PORT:
  583. return sendPort();
  584. case SEQ_RECV_PORT:
  585. return recvPort();
  586. case SEQ_SEND_PASV:
  587. return sendPasv();
  588. case SEQ_RECV_PASV:
  589. return recvPasv();
  590. case SEQ_SEND_REST_PASV:
  591. return sendRestPasv(segment);
  592. case SEQ_SEND_REST:
  593. return sendRest(segment);
  594. case SEQ_RECV_REST:
  595. return recvRest(segment);
  596. case SEQ_SEND_RETR:
  597. return sendRetr();
  598. case SEQ_RECV_RETR:
  599. return recvRetr();
  600. case SEQ_WAIT_CONNECTION:
  601. return waitConnection();
  602. default:
  603. abort();
  604. }
  605. return doNextSequence;
  606. }
  607. void FtpNegotiationCommand::poolConnection() const
  608. {
  609. if(getOption()->getAsBool(PREF_FTP_REUSE_CONNECTION)) {
  610. std::map<std::string, std::string> options;
  611. options["baseWorkingDir"] = ftp->getBaseWorkingDir();
  612. e->poolSocket(req, isProxyDefined(), socket, options);
  613. }
  614. }
  615. void FtpNegotiationCommand::onDryRunFileFound()
  616. {
  617. _requestGroup->getPieceStorage()->markAllPiecesDone();
  618. poolConnection();
  619. sequence = SEQ_HEAD_OK;
  620. }
  621. } // namespace aria2