SFTP fixes for Macos

This commit is contained in:
pokamest 2022-01-24 14:29:37 -08:00
parent 8e26da1759
commit 1a144da36d
4 changed files with 71 additions and 28 deletions

View file

@ -2,6 +2,7 @@
#include <QTimer>
#include <QProcess>
#include <QStorageInfo>
#include <QStandardPaths>
#include "OtherProtocolsLogic.h"
#include "core/servercontroller.h"
@ -41,17 +42,12 @@ void OtherProtocolsLogic::updateProtocolPage(const QJsonObject &config, DockerCo
set_labelTftpPortText(config.value(config_key::port).toString());
set_labelTorWebSiteAddressText(config.value(config_key::site).toString());
set_pushButtonSftpMountEnabled(true);
}
//QJsonObject OtherProtocolsLogic::getProtocolConfigFromPage(QJsonObject oldConfig)
//{
//}
void OtherProtocolsLogic::onPushButtonSftpMountDriveClicked()
{
#ifdef Q_OS_WINDOWS
QString OtherProtocolsLogic::getNextDriverLetter() const
{
QProcess drivesProc;
drivesProc.start("wmic logicaldisk get caption");
drivesProc.waitForFinished();
@ -68,53 +64,93 @@ void OtherProtocolsLogic::onPushButtonSftpMountDriveClicked()
if (letter == "C:") {
// set err info
qDebug() << "Can't find free drive letter";
return;
return "";
}
return letter;
}
#endif
//QJsonObject OtherProtocolsLogic::getProtocolConfigFromPage(QJsonObject oldConfig)
//{
//}
void OtherProtocolsLogic::onPushButtonSftpMountDriveClicked()
{
QString mountPath;
QString cmd;
QString host = m_settings.serverCredentials(uiLogic()->selectedServerIndex).hostName;
#ifdef Q_OS_WINDOWS
mountPath = getNextDriverLetter() + ":";
// QString cmd = QString("net use \\\\sshfs\\%1@x.x.x.x!%2 /USER:%1 %3")
// .arg(labelTftpUserNameText())
// .arg(labelTftpPortText())
// .arg(labelTftpPasswordText());
cmd = "C:\\Program Files\\SSHFS-Win\\bin\\sshfs.exe";
#elif defined AMNEZIA_DESKTOP
mountPath = QString("%1/sftp:%2:%3")
.arg(QStandardPaths::writableLocation(QStandardPaths::HomeLocation))
.arg(host)
.arg(labelTftpPortText());
QDir dir(mountPath);
if (!dir.exists()){
dir.mkpath(mountPath);
}
cmd = "/usr/local/bin/sshfs";
#endif
#ifdef AMNEZIA_DESKTOP
set_pushButtonSftpMountEnabled(false);
QProcess *p = new QProcess;
m_sftpMountProcesses.append(p);
p->setProcessChannelMode(QProcess::MergedChannels);
connect(p, &QProcess::readyRead, this, [this, p, letter](){
connect(p, &QProcess::readyRead, this, [this, p, mountPath](){
QString s = p->readAll();
if (s.contains("The service sshfs has been started")) {
QDesktopServices::openUrl(QUrl("file:///" + letter + ":"));
QDesktopServices::openUrl(QUrl("file:///" + mountPath));
set_pushButtonSftpMountEnabled(true);
}
qDebug() << s;
});
// QString cmd = QString("net use \\\\sshfs\\%1@x.x.x.x!%2 /USER:%1 %3")
// .arg(labelTftpUserNameText())
// .arg(labelTftpPortText())
// .arg(labelTftpPasswordText());
p->setProgram("C:\\Program Files\\SSHFS-Win\\bin\\sshfs.exe");
QString host = m_settings.serverCredentials(uiLogic()->selectedServerIndex).hostName;
p->setProgram(cmd);
QString args = QString(
"%1@%2:/ %3: "
"%1@%2:/ %3 "
"-o port=%4 "
"-f "
"-o reconnect"
"-orellinks "
"-ofstypename=SSHFS "
"-o reconnect "
"-o rellinks "
"-o fstypename=SSHFS "
"-o ssh_command=/usr/bin/ssh.exe "
"-oUserKnownHostsFile=/dev/null "
"-oStrictHostKeyChecking=no "
"-o UserKnownHostsFile=/dev/null "
"-o StrictHostKeyChecking=no "
"-o password_stdin")
.arg(labelTftpUserNameText())
.arg(host)
.arg(letter)
.arg(mountPath)
.arg(labelTftpPortText());
p->setNativeArguments(args);
// args.replace("\n", " ");
// args.replace("\r", " ");
//#ifndef Q_OS_WIN
// args.replace("reconnect-orellinks", "");
//#endif
p->setArguments(args.split(" ", QString::SkipEmptyParts));
p->start();
p->waitForStarted(50);
if (p->state() != QProcess::Running) {
qDebug() << "onPushButtonSftpMountDriveClicked process not started";
qDebug() << args;
}
else {
p->write((labelTftpPasswordText() + "\n").toUtf8());
@ -123,7 +159,6 @@ void OtherProtocolsLogic::onPushButtonSftpMountDriveClicked()
//qDebug().noquote() << "onPushButtonSftpMountDriveClicked" << args;
set_pushButtonSftpMountEnabled(true);
#endif
}