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

View File

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