diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosshconnection.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemosshconnection.cpp
index def3119a3f6e9ac8af940b81c14db33ea0db9a8e..1ad9d2b8681252fd19b6420cccd8db37e16d9e18 100644
--- a/src/plugins/qt4projectmanager/qt-maemo/maemosshconnection.cpp
+++ b/src/plugins/qt4projectmanager/qt-maemo/maemosshconnection.cpp
@@ -159,16 +159,25 @@ MaemoSftpConnection::~MaemoSftpConnection()
 
 }
 
+class FileManager
+{
+public:
+    FileManager(const QString &filePath)
+        : m_file(fopen(filePath.toLatin1().data(), "rb")) {}
+    ~FileManager() { if (m_file) fclose(m_file); }
+    FILE *file() const { return m_file; }
+private:
+    FILE * const m_file;
+};
+
 void MaemoSftpConnection::transferFiles(const QList<SshDeploySpec> &deploySpecs)
 {
     for (int i = 0; i < deploySpecs.count(); ++i) {
         const SshDeploySpec &deploySpec = deploySpecs.at(i);
         const QString &curSrcFile = deploySpec.srcFilePath();
-        QSharedPointer<FILE> filePtr(fopen(curSrcFile.toLatin1().data(), "rb"),
-                                     &std::fclose);
-        if (filePtr.isNull())
+        FileManager fileMgr(curSrcFile);
+        if (!fileMgr.file())
             throw MaemoSshException(tr("Could not open file '%1'").arg(curSrcFile));
-
         const QString &curTgtFile = deploySpec.tgtFilePath();
 
         // TODO: Is the mkdir() method recursive? If not, we have to
@@ -180,7 +189,7 @@ void MaemoSftpConnection::transferFiles(const QList<SshDeploySpec> &deploySpecs)
 
         qDebug("Deploying file %s to %s.", qPrintable(curSrcFile), qPrintable(curTgtFile));
 
-        if (!sftp->put(filePtr.data(), curTgtFile.toLatin1().data())) {
+        if (!sftp->put(fileMgr.file(), curTgtFile.toLatin1().data())) {
             const QString &error = tr("Could not copy local file '%1' "
                     "to remote file '%2': %3").arg(curSrcFile, curTgtFile)
                     .arg(lastError());