Commit 77b59b02 authored by ck's avatar ck

Maemo: Implement sftp file transfer (untested).

parent 19f1df4f
......@@ -47,8 +47,10 @@
#include "/opt/ne7ssh/include/ne7ssh.h"
#include <QtCore/QMutex>
#include <QtCore/QMutexLocker>
#include <QtCore/QStringBuilder>
#include <QtCore/QStringList>
#include <cstdio>
namespace Qt4ProjectManager {
namespace Internal {
......@@ -134,9 +136,12 @@ MaemoInteractiveSshConnection::Ptr MaemoInteractiveSshConnection::create(const M
}
MaemoSftpConnection::MaemoSftpConnection(const MaemoDeviceConfig &devConf)
: MaemoSshConnection(devConf, false)
: MaemoSshConnection(devConf, false),
sftp(new Ne7SftpSubsystem)
{
// TODO: Initialize sftp subsystem
if (!ssh.initSftp(*sftp, channel()) || !sftp->setTimeout(devConf.timeout))
throw MaemoSshException(tr("Error setting up SFTP subsystem: %1")
.arg(lastError()));
}
MaemoSftpConnection::~MaemoSftpConnection()
......@@ -147,7 +152,22 @@ MaemoSftpConnection::~MaemoSftpConnection()
void MaemoSftpConnection::transferFiles(const QStringList &filePaths,
const QStringList &targetDirs)
{
Q_ASSERT(filePaths.count() == targetDirs.count());
for (int i = 0; i < filePaths.count(); ++i) {
const QString &curFile = filePaths.at(i);
QSharedPointer<FILE> filePtr(fopen(curFile.toLatin1().data(), "rb"),
&std::fclose);
if (filePtr.isNull())
throw MaemoSshException(tr("Could not open file '%1'").arg(curFile));
const QString &targetFile
= targetDirs.at(i) % QLatin1String("/") % curFile;
if (!sftp->put(filePtr.data(), targetFile.toLatin1().data())) {
const QString &error = tr("Could not copy local file '%1' "
"to remote file '%2': %3").arg(curFile, targetFile)
.arg(lastError());
throw MaemoSshException(error);
}
}
}
MaemoSftpConnection::Ptr MaemoSftpConnection::create(const MaemoDeviceConfig &devConf)
......@@ -155,7 +175,6 @@ MaemoSftpConnection::Ptr MaemoSftpConnection::create(const MaemoDeviceConfig &de
return Ptr(new MaemoSftpConnection(devConf));
}
} // namespace Internal
} // namespace Qt4ProjectManager
......
......@@ -45,15 +45,17 @@
// #define USE_SSH_LIB
#ifdef USE_SSH_LIB
#include <QtCore/QCoreApplication>
#include <QtCore/QObject>
#include <QtCore/QScopedPointer>
#include <QtCore/QSharedPointer>
#include <QtCore/QString>
QT_BEGIN_NAMESPACE
class QStringList;
QT_END_NAMESPACE
class ne7ssh;
class Ne7SftpSubsystem;
namespace Qt4ProjectManager {
namespace Internal {
......@@ -124,6 +126,8 @@ signals:
private:
MaemoSftpConnection(const MaemoDeviceConfig &devConf);
QScopedPointer<Ne7SftpSubsystem> sftp;
};
} // namespace Internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment