Page 1 of 2 12 LastLast
Results 1 to 20 of 28

Thread: How to connect to ftp server and read the filenames in the ftp folder?

  1. #1
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default How to connect to ftp server and read the filenames in the ftp folder?

    How to connect to ftp server and read the filenames from the ftp folder and create labels with the filenames and display those on the dialog?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    What have you tried?

  3. #3
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    I have just made the connection using ftp. How to read the filenames in the particular folder?

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    Issue the FTP LIST command. So far you have not explained how you have tried to use Qt to do any of this.

  5. #5
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    I have added the following code to login into the ftp site.
    Qt Code:
    1. QFtp *ftp = new QFtp(this);
    2. ftp->connectToHost("ftp.qt.nokia.com");
    3. ftp->login();
    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: How to connect to ftp server and read the filenames in the ftp folder?

    And then? Have you seen QFtp::list()?
    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 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    I have found the way to get the list of filenames from the ftp folder.
    Qt Code:
    1. #include "ftpwindow.h"
    2. #include "ui_ftpwindow.h"
    3. #include "qftp.h"
    4. #include "qurl.h"
    5. #include "QMessageBox"
    6. #include "QFile"
    7.  
    8. FTPWindow::FTPWindow(QWidget *parent) :
    9. QDialog(parent),
    10. ui(new Ui::FTPWindow),ftp(0)
    11. {
    12. ui->setupUi(this);
    13.  
    14. QUrl url("ftp.qt.nokia.com");
    15.  
    16. }
    17.  
    18. FTPWindow::~FTPWindow()
    19. {
    20. delete ui;
    21. }
    22.  
    23. void FTPWindow::changeEvent(QEvent *e)
    24. {
    25. QDialog::changeEvent(e);
    26. switch (e->type()) {
    27. case QEvent::LanguageChange:
    28. ui->retranslateUi(this);
    29. break;
    30. default:
    31. break;
    32. }
    33. }
    34.  
    35. void FTPWindow::addToList(const QUrlInfo &urlInfo)
    36. {
    37. QString filelist;
    38. filelist += urlInfo.name();
    39. //QMessageBox::information(this, tr("FTP"),filelist,QMessageBox::Ok);
    40.  
    41. QFile newfile("ftpfilenames1.txt");
    42. newfile.open(QIODevice::WriteOnly | QIODevice::Append);
    43. newfile.write(filelist.toAscii().data());
    44. newfile.write("\r\n");
    45. newfile.close();
    46.  
    47. }
    48.  
    49. void FTPWindow::on_Connect_clicked()
    50. {
    51. #ifdef Q_OS_SYMBIAN
    52. if(!bDefaultIapSet) {
    53. qt_SetDefaultIap();
    54. bDefaultIapSet = true;
    55. }
    56. #endif
    57. if (ftp) {
    58. ftp->abort();
    59. ftp->deleteLater();
    60. ftp = 0;
    61. //![0]
    62.  
    63. #ifndef QT_NO_CURSOR
    64. setCursor(Qt::ArrowCursor);
    65. #endif
    66. return;
    67. }
    68.  
    69. #ifndef QT_NO_CURSOR
    70. setCursor(Qt::WaitCursor);
    71. #endif
    72.  
    73. //![1]
    74. ftp = new QFtp(this);
    75. connect(ftp, SIGNAL(commandFinished(int,bool)),
    76. this, SLOT(ftpCommandFinished(int,bool)));
    77. connect(ftp, SIGNAL(listInfo(QUrlInfo)),
    78. this, SLOT(addToList(QUrlInfo)));
    79.  
    80. QUrl url("ftp.qt.nokia.com");
    81. if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) {
    82. ftp->connectToHost("ftp.qt.nokia.com", 21);
    83. ftp->login();
    84. } else {
    85. ftp->connectToHost(url.host(), url.port(21));
    86.  
    87. if (!url.userName().isEmpty())
    88. ftp->login(QUrl::fromPercentEncoding(url.userName().toLatin1()), url.password());
    89. else
    90. ftp->login();
    91. if (!url.path().isEmpty())
    92. ftp->cd(url.path());
    93. }
    94.  
    95.  
    96. }
    97.  
    98. void FTPWindow::ftpCommandFinished(int, bool error)
    99. {
    100. #ifndef QT_NO_CURSOR
    101. setCursor(Qt::ArrowCursor);
    102. #endif
    103.  
    104. if (ftp->currentCommand() == QFtp::ConnectToHost) {
    105. if (error) {
    106. QMessageBox::information(this, tr("FTP"),
    107. tr("Unable to connect to the FTP server "
    108. "at %1. Please check that the host "
    109. "name is correct."),
    110. on_Connect_clicked();
    111. return;
    112. }
    113. return;
    114. }
    115.  
    116. if (ftp->currentCommand() == QFtp::Login){
    117. ftp->list(); }
    118.  
    119. else if (ftp->currentCommand() == QFtp::List) {
    120.  
    121.  
    122. }
    123.  
    124. }
    To copy to clipboard, switch view to plain text mode 

    This creates a file ftpfilenames1.txt and it contains all the filenames from the ftp site. Works fine.

  8. #8
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    I am getting all the lists including file and folder names. I just want to list only the filenames. How to filter in order to get the filenames alone?

  9. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    Have you looked at the docs for QUrlInfo, the class you are using to get the directory entry name, or did you just copy'n'paste from somewhere else?

  10. #10
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    Thanks.. I have used isDir() and it worked... voilaaaaa

  11. The following user says thank you to Gokulnathvc for this useful post:


  12. #11
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    18
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    Quote Originally Posted by wysota View Post
    And then? Have you seen QFtp::list()?
    Hi Wysota,

    i am having a small doubt. In the QT installed directory i found the example of "QFTP", which is used to connect to FTP Server.
    Here my doubt is, can we connect to a remote machine by using an "host-name" of a remote system instead of "ftp.qt.nokia.com" in the same FTP example ?
    Last edited by mahi6a1985; 15th December 2012 at 10:09.

  13. #12
    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: How to connect to ftp server and read the filenames in the ftp folder?

    "ftp.qt.nokia.com" is a host name.
    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.


  14. #13
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    18
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    yes i agree but i have given the ip address of the other machine in that ftp example i can able to connect it but cant see the files list.

    My aim is to connect to a remote system (windows OS) from my Linux system and copy a directory of windows system (i.e., which consists of 2 or 3 text files) to my linux system.

  15. #14
    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: How to connect to ftp server and read the filenames in the ftp folder?

    Quote Originally Posted by mahi6a1985 View Post
    yes i agree but i have given the ip address of the other machine in that ftp example i can able to connect it but cant see the files list.
    Maybe it's a matter of being able to perform active/passive FTP connection.
    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.


  16. #15
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    18
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    Quote Originally Posted by wysota View Post
    Maybe it's a matter of being able to perform active/passive FTP connection.
    yes you are absolutely correct my ftp server application which in windows wont accept passive FTP connection.
    So, i have to make some changes then... ??

    Thanks wysota

  17. #16
    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: How to connect to ftp server and read the filenames in the ftp folder?

    You have to act accordingly to the protocol approach you wish to support.
    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.


  18. #17
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    18
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    Quote Originally Posted by wysota View Post
    You have to act accordingly to the protocol approach you wish to support.
    Hi wysota,

    Now i am able to connect to ftp server and can view the entire remote system FTP server files and also i can download them but the problem is some of them were 0-bytes means only file is downloaded non of the content is downloaded and some of them were half downloaded.
    But all the files listed in the FTP site were downloaded to my local directory.

    what could be the problem ?

    i have seen the QFTP example their its only one file at a time so it seems fine. But in my case i want to download all the files of the ftp folder.

  19. #18
    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: How to connect to ftp server and read the filenames in the ftp folder?

    And how are you doing 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.


  20. #19
    Join Date
    Sep 2012
    Posts
    32
    Thanks
    18
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to connect to ftp server and read the filenames in the ftp folder?

    Quote Originally Posted by wysota View Post
    And how are you doing that?
    After getting the list using ftp->list();
    i am using a loop and calling each of the listed files one by one using ftp->get(urlInfo.name(),file);

  21. #20
    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: How to connect to ftp server and read the filenames in the ftp folder?

    Show the actual code, please.
    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.


Similar Threads

  1. Connect To Sql Server With QT
    By METEOR7 in forum Qt Programming
    Replies: 6
    Last Post: 13th December 2011, 12:39
  2. Trying to Connect To SQL Server 2005
    By rossd in forum Installation and Deployment
    Replies: 0
    Last Post: 6th March 2009, 19:56
  3. QFtp: downloading a whole folder from a remote server.
    By balazsbela in forum Qt Programming
    Replies: 5
    Last Post: 5th August 2007, 09:34
  4. cannot connect to X server
    By jcr in forum Qt Programming
    Replies: 1
    Last Post: 18th April 2007, 14:22
  5. connect to sql server
    By raphaelf in forum Qt Programming
    Replies: 15
    Last Post: 27th February 2006, 18:06

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.