diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosshconnection.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemosshconnection.cpp index b99a3555b1a694322eebc5d8230255dd0dc3000c..b125de0c9f57c78e53180734382b3242ca534270 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemosshconnection.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemosshconnection.cpp @@ -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 diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosshconnection.h b/src/plugins/qt4projectmanager/qt-maemo/maemosshconnection.h index 8129775d0f1514acd33af5ea77bf215eb7bc3c35..1c395c30d65b49ebdc5abdafc70d10a1b368798b 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemosshconnection.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemosshconnection.h @@ -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