Results 1 to 7 of 7

Thread: QFtp:upload file to server

  1. #1
    Join Date
    Oct 2009
    Location
    China
    Posts
    20
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Question QFtp:upload file to server

    I am confusing of uploading file to server.
    I want know how I specified the path in the server.The file ,that will be uploaded,should be open,and copy to memory,then upload to the file which I created in the server...
    May be I don't explain it clear,I just want to konw the process how the file upload to the server.
    Thank you!!
    Qt Code:
    1. int i = 0;
    2. QString filename;
    3. QString files = QFileDialog::getOpenFileName(this, tr("Select File"),
    4. "D://");
    5.  
    6. if (files.isEmpty())
    7. return;
    8.  
    9. while(files.indexOf("/", i) != (-1)) //find the file name not include the full url
    10. i = files.indexOf("/",i) + 1;
    11. while(i < files.size())
    12. {
    13. filename.append(files.at(i));
    14. i++;
    15. }
    16.  
    17. file = new QFile(filename);
    18. Q_ASSERT(file != NULL);
    19.  
    20. if(!file->open(QIODevice::ReadWrite)) //finished create the file in the debug file
    21. {
    22. qDebug() << "opern err" << file->fileName();
    23. return;
    24. }
    25.  
    26. ftp->put(file,filename);
    To copy to clipboard, switch view to plain text mode 
    After the ftp->put , I find there is no file in the server directory.
    Last edited by ensky_cy; 14th December 2009 at 05:12.

  2. #2
    Join Date
    Oct 2009
    Location
    China
    Posts
    20
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Smile Re: QFtp:upload file to server

    I get the error information:"Uploading file failed:Cannot STOR. No permission.".So I find my ftp server have some problem, I create a anonymous client and have read/write permission, then upload file success.
    But the file ,which will upload, should in my debug directory,how I can implement upload the file that in anywhere?The open function neet FILE * fh or int fd,not the file path, like
    'D://Qt '.
    Last edited by ensky_cy; 14th December 2009 at 06:00.

  3. #3
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFtp:upload file to server

    Quote Originally Posted by ensky_cy View Post
    I get the error information:"Uploading file failed:Cannot STOR. No permission.".So I find my ftp server have some problem, I create a anonymous client and have read/write permission, then upload file success.
    But the file ,which will upload, should in my debug directory,how I can implement upload the file that in anywhere?The open function neet FILE * fh or int fd,not the file path, like
    'D://Qt '.
    Then why are you manually removing the full path. I have updated your code. Please try it.Kindly also check what debug messages comes.
    Qt Code:
    1. int i = 0;
    2. QString filename;
    3. QString files = QFileDialog::getOpenFileName(this, tr("Select File"),
    4. "D://");
    5. if (files.isEmpty())
    6. return;
    7. file = new QFile(filename);
    8. Q_ASSERT(file != NULL);
    9. if(!file->open(QIODevice::ReadWrite))
    10. {
    11. qDebug() << "opern err" << file->fileName();
    12. return;
    13. }
    14. qDebug() << "Upload strat";
    15. ftp->put(file,filename);
    16. qDebug() << "Upload end";
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to yogeshgokul for this useful post:

    ensky_cy (14th December 2009)

  5. #4
    Join Date
    Oct 2009
    Location
    China
    Posts
    20
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFtp:upload file to server

    I have already solved this problem.I use the QDir to change the file directory.

  6. #5
    Join Date
    Oct 2009
    Location
    China
    Posts
    20
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Talking Re: QFtp:upload file to server

    Quote Originally Posted by yogeshgokul View Post
    Then why are you manually removing the full path. I have updated your code. Please try it.Kindly also check what debug messages comes.
    Qt Code:
    1. int i = 0;
    2. QString filename;
    3. QString files = QFileDialog::getOpenFileName(this, tr("Select File"),
    4. "D://");
    5. if (files.isEmpty())
    6. return;
    7. file = new QFile(filename);
    8. Q_ASSERT(file != NULL);
    9. if(!file->open(QIODevice::ReadWrite))
    10. {
    11. qDebug() << "opern err" << file->fileName();
    12. return;
    13. }
    14. qDebug() << "Upload strat";
    15. ftp->put(file,filename);
    16. qDebug() << "Upload end";
    To copy to clipboard, switch view to plain text mode 
    Thank you!
    The files is like:"D:/Qt/TCP/xxx.rar",and the filename is "xxx.rar".
    We create the file(xxx.rar), not the file(D:/Qt/TCP/xxx.rar).So , I need to pick up the xxx.rar.

  7. #6
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFtp:upload file to server

    Quote Originally Posted by ensky_cy View Post
    Thank you!
    The files is like:"D:/Qt/TCP/xxx.rar",and the filename is "xxx.rar".
    We create the file(xxx.rar), not the file(D:/Qt/TCP/xxx.rar).So , I need to pick up the xxx.rar.
    For that you doesn't need to write so much as you have written.
    Just 2 lines are enough
    Qt Code:
    1. QFileInfo fi("/tmp/archive.tar.gz");
    2. QString name = fi.fileName();
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to yogeshgokul for this useful post:

    ensky_cy (14th December 2009)

  9. #7
    Join Date
    Oct 2009
    Location
    China
    Posts
    20
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Cool Re: QFtp:upload file to server

    yes ,QFileInfo is useful.

Similar Threads

  1. How to upload file to HTTP server (POST Method)
    By Alex Snet in forum Qt Programming
    Replies: 8
    Last Post: 24th January 2011, 22:49
  2. Read binary from file
    By weldpua2008 in forum Newbie
    Replies: 2
    Last Post: 3rd April 2009, 23:50
  3. How to download any file through ftp server
    By thomasjoy in forum Qt Programming
    Replies: 1
    Last Post: 24th July 2007, 01:23
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  5. Enctrypted file uploads to a server
    By hardgeus in forum Qt Programming
    Replies: 3
    Last Post: 11th December 2006, 23:10

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.