FtpNegotiationCommand.cc 18 KB

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