SftpFileTransfer: Fix error reporting

Use "-b" option of sftp command for providing batch file
instead of setting a standard input file for sftp process.

In order to fix showing the authentication dialog
we explicitly pass -o BatchMode=no before the "-b" option,
which should re-enable the interactive mode before
processing batch file.

Change-Id: Iaf3c93929c08fd61373003e394a08439d05fe27e
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Jarek Kobus
2022-05-30 15:19:02 +02:00
parent 1976630bbc
commit 8a1f091bf0
2 changed files with 14 additions and 17 deletions

View File

@@ -64,24 +64,21 @@ QStringList SshParameters::connectionOptions(const FilePath &binary) const
"-o", "Port=" + QString::number(port())};
if (!userName().isEmpty())
args.append({"-o", "User=" + userName()});
args << "-o" << "User=" + userName();
const bool keyOnly = authenticationType ==
SshParameters::AuthenticationTypeSpecificKey;
if (keyOnly) {
args << "-o" << "IdentitiesOnly=yes";
args << "-i" << privateKeyFile.path();
}
if (keyOnly || SshSettings::askpassFilePath().isEmpty())
args << "-o" << "BatchMode=yes";
const bool keyOnly = authenticationType == SshParameters::AuthenticationTypeSpecificKey;
if (keyOnly)
args << "-o" << "IdentitiesOnly=yes" << "-i" << privateKeyFile.path();
bool useTimeout = timeout != 0;
if (useTimeout && HostOsInfo::isWindowsHost()
&& binary.toString().toLower().contains("/system32/")) {
useTimeout = false;
}
const QString batchModeEnabled = (keyOnly || SshSettings::askpassFilePath().isEmpty())
? QLatin1String("yes") : QLatin1String("no");
args << "-o" << "BatchMode=" + batchModeEnabled;
const bool isWindows = HostOsInfo::isWindowsHost()
&& binary.toString().toLower().contains("/system32/");
const bool useTimeout = (timeout != 0) && !isWindows;
if (useTimeout)
args << "-o" << ("ConnectTimeout=" + QString::number(timeout));
args << "-o" << "ConnectTimeout=" + QString::number(timeout);
return args;
}

View File

@@ -1609,8 +1609,8 @@ private:
+ ProcessArgs::quoteArgUnix(file.m_target.path()).toLocal8Bit() + '\n');
}
m_batchFile->close();
process().setStandardInputFile(m_batchFile->fileName());
process().setCommand(CommandLine(sftpBinary, fullConnectionOptions() << host()));
process().setCommand(CommandLine(sftpBinary, fullConnectionOptions()
<< "-b" << m_batchFile->fileName() << host()));
process().start();
}