Results 1 to 17 of 17

Thread: Ftp PUT gets stuck on Windows

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2012
    Location
    Prague, Czech Republic
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Ftp PUT gets stuck on Windows

    Hi,

    I have written application that uploads files from directory to FTP on my server. It works fine on Linux, but when I try it on Windows it gets stuck almost always. It just stops uploading files (no errors). I have already tried using QFtp and QNetworkAccessManager.

    Do you have any idea what could be wrong, please?

    Thanks in advance,
    vojta

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Ftp PUT gets stuck on Windows

    You could be filling some buffer somewhere in the system.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2012
    Location
    Prague, Czech Republic
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Ftp PUT gets stuck on Windows

    Hmm, yea. However, I have no idea what buffer it could be. Each file is ~400 KB PNG image. I always open QFile and put it using QFtp or QNetworkAccessManager. When put gets finished I close QFile and then do this again with another file. I have tried running app with GDB but it does not give me any meaningful information. I guess I just have to try to Google more and more. Anyway, thanks. And if you would have any other idea, please let me know.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Ftp PUT gets stuck on Windows

    Yeah... or you could show us some code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2012
    Location
    Prague, Czech Republic
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Ftp PUT gets stuck on Windows

    Well, here is my code. Thanks.

    PresentationUploader.h:
    Qt Code:
    1. #ifndef PRESENTATIONUPLOADER_H
    2. #define PRESENTATIONUPLOADER_H
    3.  
    4. #include <QObject>
    5. #include <QStringList>
    6.  
    7. class QFtp;
    8.  
    9. class PresentationUploader : public QObject
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. enum Result
    15. {
    16. Nothhing,
    17. Success = 1,
    18. AlreadyRunning,
    19. BadInput,
    20. PresentationDirectoryDoesNotExist,
    21. EmptyPresentationDirectory,
    22. AbortedByUser,
    23. CannotConnectToFtpServer,
    24. FtpServerLoginFailed,
    25. ChangeDirectoryFailed,
    26. MakeDirectoryFailed,
    27. CannotOpenFile,
    28. FileUploadFailed
    29. };
    30.  
    31. PresentationUploader();
    32.  
    33. void setPresentationId(int presentationId);
    34. void setDirectory(const QString& directory);
    35. void setFtpHost(const QString& host);
    36. void setFtpDirectory(const QString& directory);
    37. void setFtpCredentials(const QString& username, const QString& password);
    38.  
    39. public slots:
    40. void startUpload();
    41. void abortUpload(PresentationUploader::Result result = PresentationUploader::AbortedByUser);
    42.  
    43. private slots:
    44. void ftpProgress(qint64 doneBytes, qint64 totalBytes);
    45. void ftpCommandFinished(int commandId, bool error);
    46.  
    47. private:
    48. void makePresentationDirectory();
    49. void putNextFile();
    50.  
    51. private:
    52. int m_presentationId;
    53. QString m_directory;
    54. QString m_ftpHost;
    55. QString m_ftpDirectory;
    56. QString m_ftpUsername, m_ftpPassword;
    57. QFtp* m_ftp;
    58.  
    59. qint64 m_doneBytes;
    60. qint64 m_totalBytes;
    61. QStringList m_files;
    62.  
    63. PresentationUploader::Result m_result;
    64. bool m_aborted;
    65.  
    66. signals:
    67. void nextFile(const QString& file);
    68. void totalProgress(qint64 doneBytes, qint64 totalBytes);
    69. void transferProgress(qint64 doneBytes, qint64 totalBytes);
    70. void finished(int result);
    71. };
    72.  
    73. #endif // PRESENTATIONUPLOADER_H
    To copy to clipboard, switch view to plain text mode 

    PresentationUploader.cpp:
    Qt Code:
    1. #include "PresentationUploader.h"
    2.  
    3. #include <QBuffer>
    4. #include <QDebug>
    5. #include <QDir>
    6. #include <QFileInfo>
    7. #include <QFtp>
    8.  
    9. PresentationUploader::PresentationUploader() :
    10. m_presentationId(-1),
    11. m_ftp(0),
    12. m_result(Nothhing)
    13. {
    14. }
    15.  
    16. void PresentationUploader::setPresentationId(int presentationId)
    17. {
    18. m_presentationId = presentationId;
    19. }
    20.  
    21. void PresentationUploader::setDirectory(const QString& directory)
    22. {
    23. m_directory = directory;
    24. }
    25.  
    26. void PresentationUploader::setFtpHost(const QString& host)
    27. {
    28. m_ftpHost = host;
    29. }
    30.  
    31. void PresentationUploader::setFtpDirectory(const QString& directory)
    32. {
    33. m_ftpDirectory = directory;
    34. }
    35.  
    36. void PresentationUploader::setFtpCredentials(const QString& username, const QString& password)
    37. {
    38. m_ftpUsername = username;
    39. m_ftpPassword = password;
    40. }
    41.  
    42. void PresentationUploader::startUpload()
    43. {
    44. if (m_ftp != 0)
    45. {
    46. emit finished(AlreadyRunning);
    47. return;
    48. }
    49.  
    50. if (m_presentationId < 0 || m_directory.isEmpty() || m_ftpHost.isEmpty() || m_ftpDirectory.isEmpty() || m_ftpUsername.isEmpty() || m_ftpPassword.isEmpty())
    51. {
    52. emit finished(BadInput);
    53. return;
    54. }
    55.  
    56. QFileInfo directoryInfo(m_directory);
    57. if (!directoryInfo.exists())
    58. {
    59. emit finished(PresentationDirectoryDoesNotExist);
    60. return;
    61. }
    62.  
    63. m_doneBytes = 0;
    64. m_totalBytes = 0;
    65. m_files.clear();
    66.  
    67. QDir directory(m_directory);
    68. foreach(const QFileInfo& fileInfo, directory.entryInfoList(QDir::Files))
    69. {
    70. m_files.append(fileInfo.absoluteFilePath());
    71. m_totalBytes += fileInfo.size();
    72. }
    73.  
    74. if (m_files.isEmpty())
    75. {
    76. emit finished(EmptyPresentationDirectory);
    77. return;
    78. }
    79.  
    80. m_ftp = new QFtp(this);
    81.  
    82. connect(m_ftp, SIGNAL(commandFinished(int, bool)), this, SLOT(ftpCommandFinished(int, bool)));
    83. connect(m_ftp, SIGNAL(dataTransferProgress(qint64, qint64)), this, SLOT(ftpProgress(qint64, qint64)));
    84. connect(m_ftp, SIGNAL(dataTransferProgress(qint64, qint64)), this, SIGNAL(transferProgress(qint64, qint64)));
    85.  
    86. m_ftp->connectToHost(m_ftpHost, 21);
    87. m_ftp->login(m_ftpUsername, m_ftpPassword);
    88. m_ftp->cd(m_ftpDirectory);
    89. }
    90.  
    91. void PresentationUploader::abortUpload(PresentationUploader::Result result)
    92. {
    93. m_result = result;
    94. m_ftp->close();
    95. }
    96.  
    97. void PresentationUploader::ftpProgress(qint64 doneBytes, qint64 totalBytes)
    98. {
    99. Q_UNUSED(totalBytes);
    100.  
    101. emit totalProgress(m_doneBytes + doneBytes, m_totalBytes);
    102. }
    103.  
    104. void PresentationUploader::ftpCommandFinished(int commandId, bool error)
    105. {
    106. Q_UNUSED(commandId);
    107.  
    108. if (m_ftp->currentCommand() == QFtp::ConnectToHost)
    109. {
    110. if (error)
    111. abortUpload(CannotConnectToFtpServer);
    112. }
    113. else if (m_ftp->currentCommand() == QFtp::Login)
    114. {
    115. if (error)
    116. abortUpload(FtpServerLoginFailed);
    117. }
    118. else if (m_ftp->currentCommand() == QFtp::Cd)
    119. {
    120. if (error)
    121. abortUpload(ChangeDirectoryFailed);
    122. else
    123. makePresentationDirectory();
    124. }
    125. else if (m_ftp->currentCommand() == QFtp::Mkdir)
    126. {
    127. /*if (error)
    128.   abortUpload(MakeDirectoryFailed);
    129.   else*/
    130. putNextFile();
    131. }
    132. else if (m_ftp->currentCommand() == QFtp::Put)
    133. {
    134. m_doneBytes += m_ftp->currentDevice()->size();
    135.  
    136. m_ftp->currentDevice()->close();
    137. m_ftp->currentDevice()->deleteLater();
    138.  
    139. if (error)
    140. abortUpload(FileUploadFailed);
    141. else if (!m_files.empty())
    142. putNextFile();
    143. else if (!m_ftp->hasPendingCommands())
    144. abortUpload(Success);
    145. }
    146. else if (m_ftp->currentCommand() == QFtp::Close)
    147. {
    148. m_ftp->deleteLater();
    149. m_ftp = 0;
    150.  
    151. emit finished(m_result);
    152. }
    153. }
    154.  
    155. void PresentationUploader::makePresentationDirectory()
    156. {
    157. m_ftp->mkdir(QString::number(m_presentationId));
    158. }
    159.  
    160. void PresentationUploader::putNextFile()
    161. {
    162. QString filePath(m_files.takeFirst());
    163. QFileInfo fileInfo(filePath);
    164. QFile* file = new QFile(filePath);
    165.  
    166. emit nextFile(fileInfo.fileName());
    167.  
    168. if (!file->open(QIODevice::ReadOnly))
    169. abortUpload(CannotOpenFile);
    170.  
    171. m_ftp->put(file, QString("%1/%2").arg(m_presentationId).arg(fileInfo.fileName()));
    172.  
    173. if (m_files.isEmpty()) // put complete file after uploading last file
    174. {
    175. QByteArray* byteArray = new QByteArray("OK");
    176. QBuffer* buffer = new QBuffer(byteArray);
    177.  
    178. m_ftp->put(buffer, QString("%1/complete").arg(m_presentationId));
    179. }
    180. }
    To copy to clipboard, switch view to plain text mode 

    I move PresentationUploader object to its own thread after creation like this:
    Qt Code:
    1. QThread* uploaderThread = new QThread();
    2. PresentationUploader* uploader = new PresentationUploader();
    3.  
    4. uploader.moveToThread(uploaderThread);
    5.  
    6. connect(uploaderThread, SIGNAL(started()), uploader, SLOT(startUpload()));
    7. ...
    8. uploaderThread->start();
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Ftp PUT gets stuck on Windows

    What's the thread for? There is no need for that.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Mar 2012
    Location
    Prague, Czech Republic
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Ftp PUT gets stuck on Windows

    Main thread is quite busy because of other functions of application. I wanted to save some resources in main thread and keep it responsive as much as possible. Do you think I can run upload in main thread? I will give it a try.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Ftp PUT gets stuck on Windows

    You can definitely do all that in the main thread. If you want to offload some work to a different thread then offload cpu intensive operations from the main thread.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Mar 2012
    Location
    Prague, Czech Republic
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Ftp PUT gets stuck on Windows

    Ok, I have removed that thread and I am running upload in main thread, now. However, it still gets stuck sometimes.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Ftp PUT gets stuck on Windows

    Add debug messages to your methods (or use a debugger) to see the path the code is taking. Maybe the upload gets aborted or something. Also output volume of data that has already been sent. If the volume will be a multiple of 256 then it's probable that some buffer is full.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Mar 2012
    Location
    Prague, Czech Republic
    Posts
    9
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Ftp PUT gets stuck on Windows

    I have added debug messages and this is the end of output:

    Qt Code:
    1. FTP: command "Put" id 22 "finished (error: 0 No error)"
    2. FTP: command "Put" id 23 "queued 117956 bytes 38888923/0-0019.png"
    3. FTP: command "Put" id 23 "started"
    4. FTP: progress "Put" id 23 0 b of 117956 b
    5. currentDevice "E:/data/0-0019.png" error: "No error"
    6. FTP: progress "Put" id 23 16384 b of 117956 b
    7. currentDevice "E:/data/0-0019.png" error: "No error"
    8. FTP: progress "Put" id 23 32768 b of 117956 b
    9. currentDevice "E:/data/0-0019.png" error: "No error"
    10. FTP: progress "Put" id 23 49152 b of 117956 b
    11. currentDevice "E:/data/0-0019.png" error: "No error"
    12. FTP: progress "Put" id 23 65536 b of 117956 b
    13. currentDevice "E:/data/0-0019.png" error: "No error"
    14. FTP: progress "Put" id 23 81920 b of 117956 b
    15. currentDevice "E:/data/0-0019.png" error: "No error"
    16. FTP: progress "Put" id 23 98304 b of 117956 b
    17. currentDevice "E:/data/0-0019.png" error: "No error"
    18. FTP: progress "Put" id 23 114688 b of 117956 b
    19. currentDevice "E:/data/0-0019.png" error: "No error"
    20. FTP: progress "Put" id 23 117956 b of 117956 b
    21. currentDevice "E:/data/0-0019.png" error: "No error"
    22. FTP: command "Put" id 23 "finished (error: 0 No error)"
    23. FTP: command "Put" id 24 "queued 117956 bytes 38888923/0-0020.png"
    24. FTP: command "Put" id 24 "started"
    25. FTP: progress "Put" id 24 0 b of 117956 b
    26. currentDevice "E:/data/0-0020.png" error: "No error"
    To copy to clipboard, switch view to plain text mode 

    And here application gets stuck. It always gets stuck at the beginning of file. It looks like QFtp started Put command but does not upload anything and it really does not send any data over network (checked with Wireshark).

Similar Threads

  1. QT Questions That where I stuck...
    By kinjalp in forum Qt Programming
    Replies: 1
    Last Post: 17th December 2011, 17:46
  2. QPushButton gets stuck
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 22nd May 2010, 23:22
  3. Help plz! I’m stuck with these delegates
    By codeaddict in forum Qt Programming
    Replies: 7
    Last Post: 19th August 2008, 21:33
  4. comboboxes get stuck
    By illuzioner in forum Qt Programming
    Replies: 2
    Last Post: 30th March 2006, 01:03

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.