Changeset View
Changeset View
Standalone View
Standalone View
src/ioslaves/ftp/ftp.cpp
Show First 20 Lines • Show All 321 Lines • ▼ Show 20 Line(s) | |||||
322 | } | 322 | } | ||
323 | 323 | | |||
324 | void Ftp::setHost(const QString &_host, quint16 _port, const QString &_user, | 324 | void Ftp::setHost(const QString &_host, quint16 _port, const QString &_user, | ||
325 | const QString &_pass) | 325 | const QString &_pass) | ||
326 | { | 326 | { | ||
327 | qCDebug(KIO_FTP) << _host << "port=" << _port << "user=" << _user; | 327 | qCDebug(KIO_FTP) << _host << "port=" << _port << "user=" << _user; | ||
328 | 328 | | |||
329 | m_proxyURL.clear(); | 329 | m_proxyURL.clear(); | ||
330 | m_proxyUrls = config()->readEntry("ProxyUrls", QStringList()); | 330 | m_proxyUrls = mapConfig().value(QStringLiteral("MarkPartial"), QVariant(QStringList())).toStringList(); | ||
331 | qCDebug(KIO_FTP) << "proxy urls:" << m_proxyUrls; | 331 | qCDebug(KIO_FTP) << "proxy urls:" << m_proxyUrls; | ||
332 | 332 | | |||
333 | if (m_host != _host || m_port != _port || | 333 | if (m_host != _host || m_port != _port || | ||
334 | m_user != _user || m_pass != _pass) { | 334 | m_user != _user || m_pass != _pass) { | ||
335 | closeConnection(); | 335 | closeConnection(); | ||
336 | } | 336 | } | ||
337 | 337 | | |||
338 | m_host = _host; | 338 | m_host = _host; | ||
Show All 37 Lines | 350 | { | |||
376 | bool userNameChanged = false; | 376 | bool userNameChanged = false; | ||
377 | if (loginMode != loginDefered) { | 377 | if (loginMode != loginDefered) { | ||
378 | m_bLoggedOn = ftpLogin(&userNameChanged); | 378 | m_bLoggedOn = ftpLogin(&userNameChanged); | ||
379 | if (!m_bLoggedOn) { | 379 | if (!m_bLoggedOn) { | ||
380 | return false; // error emitted by ftpLogin | 380 | return false; // error emitted by ftpLogin | ||
381 | } | 381 | } | ||
382 | } | 382 | } | ||
383 | 383 | | |||
384 | m_bTextMode = config()->readEntry("textmode", false); | 384 | m_bTextMode = mapConfig().value(QStringLiteral("textmode"), false).toBool(); | ||
385 | connected(); | 385 | connected(); | ||
386 | 386 | | |||
387 | // Redirected due to credential change... | 387 | // Redirected due to credential change... | ||
388 | if (userNameChanged && m_bLoggedOn) { | 388 | if (userNameChanged && m_bLoggedOn) { | ||
389 | QUrl realURL; | 389 | QUrl realURL; | ||
390 | realURL.setScheme(QStringLiteral("ftp")); | 390 | realURL.setScheme(QStringLiteral("ftp")); | ||
391 | if (m_user != QLatin1String(FTP_LOGIN)) { | 391 | if (m_user != QLatin1String(FTP_LOGIN)) { | ||
392 | realURL.setUserName(m_user); | 392 | realURL.setUserName(m_user); | ||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Line(s) | |||||
513 | { | 513 | { | ||
514 | infoMessage(i18n("Sending login information")); | 514 | infoMessage(i18n("Sending login information")); | ||
515 | 515 | | |||
516 | Q_ASSERT(!m_bLoggedOn); | 516 | Q_ASSERT(!m_bLoggedOn); | ||
517 | 517 | | |||
518 | QString user(m_user); | 518 | QString user(m_user); | ||
519 | QString pass(m_pass); | 519 | QString pass(m_pass); | ||
520 | 520 | | |||
521 | if (config()->readEntry("EnableAutoLogin", false)) { | 521 | if (mapConfig().value(QStringLiteral("EnableAutoLogin"), false).toBool()) { | ||
522 | QString au = config()->readEntry("autoLoginUser"); | 522 | QString au = mapConfig().value(QStringLiteral("autoLoginUser")).toString(); | ||
523 | if (!au.isEmpty()) { | 523 | if (!au.isEmpty()) { | ||
524 | user = au; | 524 | user = au; | ||
525 | pass = config()->readEntry("autoLoginPass"); | 525 | pass = mapConfig().value(QStringLiteral("autoLoginPass")).toString(); | ||
526 | } | 526 | } | ||
527 | } | 527 | } | ||
528 | 528 | | |||
529 | AuthInfo info; | 529 | AuthInfo info; | ||
530 | info.url.setScheme(QStringLiteral("ftp")); | 530 | info.url.setScheme(QStringLiteral("ftp")); | ||
531 | info.url.setHost(m_host); | 531 | info.url.setHost(m_host); | ||
532 | if (m_port > 0 && m_port != DEFAULT_FTP_PORT) { | 532 | if (m_port > 0 && m_port != DEFAULT_FTP_PORT) { | ||
533 | info.url.setPort(m_port); | 533 | info.url.setPort(m_port); | ||
534 | } | 534 | } | ||
535 | if (!user.isEmpty()) { | 535 | if (!user.isEmpty()) { | ||
536 | info.url.setUserName(user); | 536 | info.url.setUserName(user); | ||
537 | } | 537 | } | ||
538 | 538 | | |||
539 | // Check for cached authentication first and fallback to | 539 | // Check for cached authentication first and fallback to | ||
540 | // anonymous login when no stored credentials are found. | 540 | // anonymous login when no stored credentials are found. | ||
541 | if (!config()->readEntry("TryAnonymousLoginFirst", false) && | 541 | if (!mapConfig().value(QStringLiteral("TryAnonymousLoginFirst"), false).toBool() && | ||
542 | pass.isEmpty() && checkCachedAuthentication(info)) { | 542 | pass.isEmpty() && checkCachedAuthentication(info)) { | ||
543 | user = info.username; | 543 | user = info.username; | ||
544 | pass = info.password; | 544 | pass = info.password; | ||
545 | } | 545 | } | ||
546 | 546 | | |||
547 | // Try anonymous login if both username/password | 547 | // Try anonymous login if both username/password | ||
548 | // information is blank. | 548 | // information is blank. | ||
549 | if (user.isEmpty() && pass.isEmpty()) { | 549 | if (user.isEmpty() && pass.isEmpty()) { | ||
Show All 30 Lines | 566 | if (failedAuth > 0 || (!user.isEmpty() && pass.isEmpty())) { | |||
580 | 580 | | |||
581 | info.prompt = i18n("You need to supply a username and a password " | 581 | info.prompt = i18n("You need to supply a username and a password " | ||
582 | "to access this site."); | 582 | "to access this site."); | ||
583 | info.commentLabel = i18n("Site:"); | 583 | info.commentLabel = i18n("Site:"); | ||
584 | info.comment = i18n("<b>%1</b>", m_host); | 584 | info.comment = i18n("<b>%1</b>", m_host); | ||
585 | info.keepPassword = true; // Prompt the user for persistence as well. | 585 | info.keepPassword = true; // Prompt the user for persistence as well. | ||
586 | info.setModified(false); // Default the modified flag since we reuse authinfo. | 586 | info.setModified(false); // Default the modified flag since we reuse authinfo. | ||
587 | 587 | | |||
588 | const bool disablePassDlg = config()->readEntry("DisablePassDlg", false); | 588 | const bool disablePassDlg = mapConfig().value(QStringLiteral("DisablePassDlg"), false).toBool(); | ||
589 | if (disablePassDlg) { | 589 | if (disablePassDlg) { | ||
590 | error(ERR_USER_CANCELED, m_host); | 590 | error(ERR_USER_CANCELED, m_host); | ||
591 | return false; | 591 | return false; | ||
592 | } | 592 | } | ||
593 | const int errorCode = openPasswordDialogV2(info, errorMsg); | 593 | const int errorCode = openPasswordDialogV2(info, errorMsg); | ||
594 | if (errorCode) { | 594 | if (errorCode) { | ||
595 | error(errorCode, QString()); | 595 | error(errorCode, QString()); | ||
596 | return false; | 596 | return false; | ||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | 673 | if (!qstrncmp(ftpResponse(0), "215 Windows_NT", 14)) { // should do for any version | |||
681 | } | 681 | } | ||
682 | // windows won't support chmod before KDE konquers their desktop... | 682 | // windows won't support chmod before KDE konquers their desktop... | ||
683 | m_extControl |= chmodUnknown; | 683 | m_extControl |= chmodUnknown; | ||
684 | } | 684 | } | ||
685 | } else { | 685 | } else { | ||
686 | qCWarning(KIO_FTP) << "SYST failed"; | 686 | qCWarning(KIO_FTP) << "SYST failed"; | ||
687 | } | 687 | } | ||
688 | 688 | | |||
689 | if (config()->readEntry("EnableAutoLoginMacro", false)) { | 689 | if (mapConfig().value(QStringLiteral("EnableAutoLoginMacro"), false).toBool()) { | ||
690 | ftpAutoLoginMacro(); | 690 | ftpAutoLoginMacro(); | ||
691 | } | 691 | } | ||
692 | 692 | | |||
693 | // Get the current working directory | 693 | // Get the current working directory | ||
694 | qCDebug(KIO_FTP) << "Searching for pwd"; | 694 | qCDebug(KIO_FTP) << "Searching for pwd"; | ||
695 | if (!ftpSendCmd(QByteArrayLiteral("PWD")) || (m_iRespType != 2)) { | 695 | if (!ftpSendCmd(QByteArrayLiteral("PWD")) || (m_iRespType != 2)) { | ||
696 | qCDebug(KIO_FTP) << "Couldn't issue pwd command"; | 696 | qCDebug(KIO_FTP) << "Couldn't issue pwd command"; | ||
697 | error(ERR_CANNOT_LOGIN, i18n("Could not login to %1.", m_host)); // or anything better ? | 697 | error(ERR_CANNOT_LOGIN, i18n("Could not login to %1.", m_host)); // or anything better ? | ||
▲ Show 20 Lines • Show All 251 Lines • ▼ Show 20 Line(s) | 948 | { | |||
949 | // make sure that we are logged on and have no data connection... | 949 | // make sure that we are logged on and have no data connection... | ||
950 | Q_ASSERT(m_bLoggedOn); | 950 | Q_ASSERT(m_bLoggedOn); | ||
951 | ftpCloseDataConnection(); | 951 | ftpCloseDataConnection(); | ||
952 | 952 | | |||
953 | int iErrCode = 0; | 953 | int iErrCode = 0; | ||
954 | int iErrCodePASV = 0; // Remember error code from PASV | 954 | int iErrCodePASV = 0; // Remember error code from PASV | ||
955 | 955 | | |||
956 | // First try passive (EPSV & PASV) modes | 956 | // First try passive (EPSV & PASV) modes | ||
957 | if (!config()->readEntry("DisablePassiveMode", false)) { | 957 | if (!mapConfig().value(QStringLiteral("DisablePassiveMode"), false).toBool()) { | ||
958 | iErrCode = ftpOpenPASVDataConnection(); | 958 | iErrCode = ftpOpenPASVDataConnection(); | ||
959 | if (iErrCode == 0) { | 959 | if (iErrCode == 0) { | ||
960 | return 0; // success | 960 | return 0; // success | ||
961 | } | 961 | } | ||
962 | iErrCodePASV = iErrCode; | 962 | iErrCodePASV = iErrCode; | ||
963 | ftpCloseDataConnection(); | 963 | ftpCloseDataConnection(); | ||
964 | 964 | | |||
965 | if (!config()->readEntry("DisableEPSV", false)) { | 965 | if (!mapConfig().value(QStringLiteral("DisableEPSV"), false).toBool()) { | ||
966 | iErrCode = ftpOpenEPSVDataConnection(); | 966 | iErrCode = ftpOpenEPSVDataConnection(); | ||
967 | if (iErrCode == 0) { | 967 | if (iErrCode == 0) { | ||
968 | return 0; // success | 968 | return 0; // success | ||
969 | } | 969 | } | ||
970 | ftpCloseDataConnection(); | 970 | ftpCloseDataConnection(); | ||
971 | } | 971 | } | ||
972 | 972 | | |||
973 | // if we sent EPSV ALL already and it was accepted, then we can't | 973 | // if we sent EPSV ALL already and it was accepted, then we can't | ||
▲ Show 20 Lines • Show All 1116 Lines • ▼ Show 20 Line(s) | 2087 | { | |||
2090 | } | 2090 | } | ||
2091 | 2091 | | |||
2092 | // Don't use mark partial over anonymous FTP. | 2092 | // Don't use mark partial over anonymous FTP. | ||
2093 | // My incoming dir allows put but not rename... | 2093 | // My incoming dir allows put but not rename... | ||
2094 | bool bMarkPartial; | 2094 | bool bMarkPartial; | ||
2095 | if (m_user.isEmpty() || m_user == QLatin1String(FTP_LOGIN)) { | 2095 | if (m_user.isEmpty() || m_user == QLatin1String(FTP_LOGIN)) { | ||
2096 | bMarkPartial = false; | 2096 | bMarkPartial = false; | ||
2097 | } else { | 2097 | } else { | ||
2098 | bMarkPartial = config()->readEntry("MarkPartial", true); | 2098 | bMarkPartial = mapConfig().value(QStringLiteral("MarkPartial"), true).toBool(); | ||
2099 | } | 2099 | } | ||
2100 | 2100 | | |||
2101 | QString dest_orig = dest_url.path(); | 2101 | QString dest_orig = dest_url.path(); | ||
2102 | const QString dest_part = dest_orig + QLatin1String(".part"); | 2102 | const QString dest_part = dest_orig + QLatin1String(".part"); | ||
2103 | 2103 | | |||
2104 | if (ftpSize(dest_orig, 'I')) { | 2104 | if (ftpSize(dest_orig, 'I')) { | ||
2105 | if (m_size == 0) { | 2105 | if (m_size == 0) { | ||
2106 | // delete files with zero size | 2106 | // delete files with zero size | ||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | |||||
2202 | } while (result > 0); | 2202 | } while (result > 0); | ||
2203 | 2203 | | |||
2204 | if (result != 0) { // error | 2204 | if (result != 0) { // error | ||
2205 | ftpCloseCommand(); // don't care about errors | 2205 | ftpCloseCommand(); // don't care about errors | ||
2206 | qCDebug(KIO_FTP) << "Error during 'put'. Aborting."; | 2206 | qCDebug(KIO_FTP) << "Error during 'put'. Aborting."; | ||
2207 | if (bMarkPartial) { | 2207 | if (bMarkPartial) { | ||
2208 | // Remove if smaller than minimum size | 2208 | // Remove if smaller than minimum size | ||
2209 | if (ftpSize(dest, 'I') && | 2209 | if (ftpSize(dest, 'I') && | ||
2210 | (processed_size < config()->readEntry("MinimumKeepSize", DEFAULT_MINIMUM_KEEP_SIZE))) { | 2210 | (processed_size < mapConfig().value(QStringLiteral("MinimumKeepSize"), DEFAULT_MINIMUM_KEEP_SIZE).toInt())) { | ||
2211 | const QByteArray cmd = "DELE " + remoteEncoding()->encode(dest); | 2211 | const QByteArray cmd = "DELE " + remoteEncoding()->encode(dest); | ||
2212 | (void) ftpSendCmd(cmd); | 2212 | (void) ftpSendCmd(cmd); | ||
2213 | } | 2213 | } | ||
2214 | } | 2214 | } | ||
2215 | return statusServerError; | 2215 | return statusServerError; | ||
2216 | } | 2216 | } | ||
2217 | 2217 | | |||
2218 | if (!ftpCloseCommand()) { | 2218 | if (!ftpCloseCommand()) { | ||
▲ Show 20 Lines • Show All 208 Lines • ▼ Show 20 Line(s) | 2419 | if (bDestExists) { | |||
2427 | } | 2427 | } | ||
2428 | } | 2428 | } | ||
2429 | 2429 | | |||
2430 | // do we have a ".part" file? | 2430 | // do we have a ".part" file? | ||
2431 | const QString sPart = sCopyFile + QLatin1String(".part"); | 2431 | const QString sPart = sCopyFile + QLatin1String(".part"); | ||
2432 | bool bResume = false; | 2432 | bool bResume = false; | ||
2433 | QFileInfo sPartInfo(sPart); | 2433 | QFileInfo sPartInfo(sPart); | ||
2434 | const bool bPartExists = sPartInfo.exists(); | 2434 | const bool bPartExists = sPartInfo.exists(); | ||
2435 | const bool bMarkPartial = config()->readEntry("MarkPartial", true); | 2435 | const bool bMarkPartial = mapConfig().value(QStringLiteral("MarkPartial"), true).toBool(); | ||
2436 | const QString dest = bMarkPartial ? sPart : sCopyFile; | 2436 | const QString dest = bMarkPartial ? sPart : sCopyFile; | ||
2437 | if (bMarkPartial && bPartExists && sPartInfo.size() > 0) { | 2437 | if (bMarkPartial && bPartExists && sPartInfo.size() > 0) { | ||
2438 | // must not be a folder! please fix a similar bug in kio_file!! | 2438 | // must not be a folder! please fix a similar bug in kio_file!! | ||
2439 | if (sPartInfo.isDir()) { | 2439 | if (sPartInfo.isDir()) { | ||
2440 | iError = ERR_DIR_ALREADY_EXIST; | 2440 | iError = ERR_DIR_ALREADY_EXIST; | ||
2441 | return statusClientError; // client side error | 2441 | return statusClientError; // client side error | ||
2442 | } | 2442 | } | ||
2443 | //doesn't work for copy? -> design flaw? | 2443 | //doesn't work for copy? -> design flaw? | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | 2499 | if (!bDestExists || !(QFile::remove(sCopyFile) && QFile::rename(sPart, sCopyFile))) { | |||
2500 | qCDebug(KIO_FTP) << "cannot rename " << sPart << " to " << sCopyFile; | 2500 | qCDebug(KIO_FTP) << "cannot rename " << sPart << " to " << sCopyFile; | ||
2501 | iError = ERR_CANNOT_RENAME_PARTIAL; | 2501 | iError = ERR_CANNOT_RENAME_PARTIAL; | ||
2502 | iRes = statusClientError; | 2502 | iRes = statusClientError; | ||
2503 | } | 2503 | } | ||
2504 | } | 2504 | } | ||
2505 | } else { | 2505 | } else { | ||
2506 | sPartInfo.refresh(); | 2506 | sPartInfo.refresh(); | ||
2507 | if (sPartInfo.exists()) { // should a very small ".part" be deleted? | 2507 | if (sPartInfo.exists()) { // should a very small ".part" be deleted? | ||
2508 | int size = config()->readEntry("MinimumKeepSize", DEFAULT_MINIMUM_KEEP_SIZE); | 2508 | int size = mapConfig().value(QStringLiteral("MinimumKeepSize"), DEFAULT_MINIMUM_KEEP_SIZE).toInt(); | ||
2509 | if (sPartInfo.size() < size) { | 2509 | if (sPartInfo.size() < size) { | ||
2510 | QFile::remove(sPart); | 2510 | QFile::remove(sPart); | ||
2511 | } | 2511 | } | ||
2512 | } | 2512 | } | ||
2513 | } | 2513 | } | ||
2514 | } | 2514 | } | ||
2515 | 2515 | | |||
2516 | if (iRes == statusSuccess) { | 2516 | if (iRes == statusSuccess) { | ||
▲ Show 20 Lines • Show All 175 Lines • Show Last 20 Lines |