Index: sftp/kio_sftp.cpp =================================================================== --- sftp/kio_sftp.cpp +++ sftp/kio_sftp.cpp @@ -518,99 +518,99 @@ mPassword = pass; } -bool sftpProtocol::sftpOpenConnection (const AuthInfo& info) +bool sftpProtocol::sftpOpenConnection(const AuthInfo& info) { - mSession = ssh_new(); - if (mSession == nullptr) { - error(KIO::ERR_OUT_OF_MEMORY, i18n("Could not create a new SSH session.")); - return false; - } - - long timeout_sec = 30, timeout_usec = 0; - - qCDebug(KIO_SFTP_LOG) << "Creating the SSH session and setting options"; + mSession = ssh_new(); + if (mSession == nullptr) { + error(KIO::ERR_OUT_OF_MEMORY, i18n("Could not create a new SSH session.")); + return false; + } - // Set timeout - int rc = ssh_options_set(mSession, SSH_OPTIONS_TIMEOUT, &timeout_sec); - if (rc < 0) { - error(KIO::ERR_INTERNAL, i18n("Could not set a timeout.")); - return false; - } - rc = ssh_options_set(mSession, SSH_OPTIONS_TIMEOUT_USEC, &timeout_usec); - if (rc < 0) { - error(KIO::ERR_INTERNAL, i18n("Could not set a timeout.")); - return false; - } + long timeout_sec = 30, timeout_usec = 0; - // Don't use any compression - rc = ssh_options_set(mSession, SSH_OPTIONS_COMPRESSION_C_S, "none"); - if (rc < 0) { - error(KIO::ERR_INTERNAL, i18n("Could not set compression.")); - return false; - } + qCDebug(KIO_SFTP_LOG) << "Creating the SSH session and setting options"; - rc = ssh_options_set(mSession, SSH_OPTIONS_COMPRESSION_S_C, "none"); - if (rc < 0) { - error(KIO::ERR_INTERNAL, i18n("Could not set compression.")); - return false; - } + // Set timeout + int rc = ssh_options_set(mSession, SSH_OPTIONS_TIMEOUT, &timeout_sec); + if (rc < 0) { + error(KIO::ERR_INTERNAL, i18n("Could not set a timeout.")); + return false; + } + rc = ssh_options_set(mSession, SSH_OPTIONS_TIMEOUT_USEC, &timeout_usec); + if (rc < 0) { + error(KIO::ERR_INTERNAL, i18n("Could not set a timeout.")); + return false; + } - // Set host and port - rc = ssh_options_set(mSession, SSH_OPTIONS_HOST, mHost.toUtf8().constData()); - if (rc < 0) { - error(KIO::ERR_INTERNAL, i18n("Could not set host.")); - return false; - } + // Don't use any compression + rc = ssh_options_set(mSession, SSH_OPTIONS_COMPRESSION_C_S, "none"); + if (rc < 0) { + error(KIO::ERR_INTERNAL, i18n("Could not set compression.")); + return false; + } - if (mPort > 0) { - rc = ssh_options_set(mSession, SSH_OPTIONS_PORT, &mPort); + rc = ssh_options_set(mSession, SSH_OPTIONS_COMPRESSION_S_C, "none"); if (rc < 0) { - error(KIO::ERR_INTERNAL, i18n("Could not set port.")); - return false; + error(KIO::ERR_INTERNAL, i18n("Could not set compression.")); + return false; } - } - // Set the username - if (!info.username.isEmpty()) { - rc = ssh_options_set(mSession, SSH_OPTIONS_USER, info.username.toUtf8().constData()); + // Set host and port + rc = ssh_options_set(mSession, SSH_OPTIONS_HOST, mHost.toUtf8().constData()); if (rc < 0) { - error(KIO::ERR_INTERNAL, i18n("Could not set username.")); - return false; + error(KIO::ERR_INTERNAL, i18n("Could not set host.")); + return false; } - } - // Read ~/.ssh/config - rc = ssh_options_parse_config(mSession, nullptr); - if (rc < 0) { - error(KIO::ERR_INTERNAL, i18n("Could not parse the config file.")); - return false; - } + if (mPort > 0) { + rc = ssh_options_set(mSession, SSH_OPTIONS_PORT, &mPort); + if (rc < 0) { + error(KIO::ERR_INTERNAL, i18n("Could not set port.")); + return false; + } + } - ssh_set_callbacks(mSession, mCallbacks); + // Set the username + if (!info.username.isEmpty()) { + rc = ssh_options_set(mSession, SSH_OPTIONS_USER, info.username.toUtf8().constData()); + if (rc < 0) { + error(KIO::ERR_INTERNAL, i18n("Could not set username.")); + return false; + } + } - qCDebug(KIO_SFTP_LOG) << "Trying to connect to the SSH server"; + // Read ~/.ssh/config + rc = ssh_options_parse_config(mSession, nullptr); + if (rc < 0) { + error(KIO::ERR_INTERNAL, i18n("Could not parse the config file.")); + return false; + } - unsigned int effectivePort; - if (mPort > 0) { - effectivePort = mPort; - } else { - effectivePort = DEFAULT_SFTP_PORT; - ssh_options_get_port(mSession, &effectivePort); - } + ssh_set_callbacks(mSession, mCallbacks); - qCDebug(KIO_SFTP_LOG) << "username=" << mUsername << ", host=" << mHost << ", port=" << effectivePort; + qCDebug(KIO_SFTP_LOG) << "Trying to connect to the SSH server"; - infoMessage(xi18n("Opening SFTP connection to host %1:%2", mHost, QString::number(effectivePort))); + unsigned int effectivePort; + if (mPort > 0) { + effectivePort = mPort; + } else { + effectivePort = DEFAULT_SFTP_PORT; + ssh_options_get_port(mSession, &effectivePort); + } - /* try to connect */ - rc = ssh_connect(mSession); - if (rc < 0) { - error(KIO::ERR_SLAVE_DEFINED, QString::fromUtf8(ssh_get_error(mSession))); - closeConnection(); - return false; - } + qCDebug(KIO_SFTP_LOG) << "username=" << mUsername << ", host=" << mHost << ", port=" << effectivePort; - return true; + infoMessage(xi18n("Opening SFTP connection to host %1:%2", mHost, QString::number(effectivePort))); + + /* try to connect */ + rc = ssh_connect(mSession); + if (rc < 0) { + error(KIO::ERR_SLAVE_DEFINED, QString::fromUtf8(ssh_get_error(mSession))); + closeConnection(); + return false; + } + + return true; }