Results 1 to 6 of 6

Thread: File exists on server

  1. #1
    Join Date
    Aug 2011
    Posts
    14
    Thanks
    1

    Default File exists on server

    Simple question:

    Is there anyway to tell if a file exists on a server or network address such as //192.168.0.2/foo/bar.txt

    I use QFile::exists( "\\192.168.0.2\foo\bar.txt" ) which works perfectly when connected to the server but say I was in an airport and not connected to the same network, the exists() function hangs and does not timeout.

    Is there any way to detect if there is a connection to the server?

    Thanks in advance

  2. #2
    Join Date
    Aug 2011
    Location
    Seoul, Korea
    Posts
    46
    Thanks
    9
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: File exists on server

    Quote Originally Posted by Chops211 View Post
    Simple question:

    Is there anyway to tell if a file exists on a server or network address such as //192.168.0.2/foo/bar.txt

    I use QFile::exists( "\\192.168.0.2\foo\bar.txt" ) which works perfectly when connected to the server but say I was in an airport and not connected to the same network, the exists() function hangs and does not timeout.

    Is there any way to detect if there is a connection to the server?

    Thanks in advance
    I believe this is what you are looking for.

    http://www.qtcentre.org/threads/2542...ork-connection

    Regards,
    Dong Back Kim

  3. #3
    Join Date
    Aug 2011
    Posts
    14
    Thanks
    1

    Default Re: File exists on server

    Thank you. I tried this before and I wanted something much simpler that doesn't require using sockets. I want to leave as much as I can to the OS. I really would like a QFile::exists() function with a timeout. or QDir()

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: File exists on server

    I guess one of the easier things to do is use ifconfig or ipconfig and parse the results.

    The correct way to do this is to use platform specific functions and this will require you to write some code.

    There are only a few things you get for free: the sun going up, death and taxes.
    So don't be lazy and start writing a little bit of code.

  5. #5
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: File exists on server

    To add up to what was posted You could either use QProcess with ping and check result or simply:
    Qt Code:
    1. void MainWindow::someFunction(){
    2. QTcpSocket *sock = new QTcpSocket( this );
    3. connect( sock, SIGNAL(hostFound()), this, SLOT( checkFile() ) );
    4. sock->connectToHost( "192.168.0.2", 421 );
    5.  
    6. }
    7.  
    8. void MainWindow::checkFile()
    9. {
    10. qDebug() << "File Exists?:" << QFile::exists( "\\192.168.0.2\foo\bar.txt" );
    11. }
    To copy to clipboard, switch view to plain text mode 

    or beter use SIGNAL( stateChanged(QAbstractSocket::SocketState) )
    Its add a few lines to Your code and is IMHO simple.
    In the near future - corporate networks reach out to the stars. Electrons and light flow throughout the universe.
    The advance of computerization however, has not yet wiped out nations and ethnic groups.

  6. The following user says thank you to Talei for this useful post:

    Chops211 (6th August 2011)

  7. #6
    Join Date
    Aug 2011
    Posts
    14
    Thanks
    1

    Default Re: File exists on server

    Thanks everyone. Using ifconfig or ipconfig doesn't really make sense when I could just use sockets but thank you for the idea.

Similar Threads

  1. Replies: 2
    Last Post: 21st February 2011, 15:52
  2. QFtp:upload file to server
    By ensky_cy in forum Qt Programming
    Replies: 6
    Last Post: 14th December 2009, 11:42
  3. Can't create folder if file with same name exists
    By Barry79 in forum Qt Programming
    Replies: 1
    Last Post: 6th May 2009, 17:33
  4. How to download any file through ftp server
    By thomasjoy in forum Qt Programming
    Replies: 1
    Last Post: 24th July 2007, 02:23
  5. Enctrypted file uploads to a server
    By hardgeus in forum Qt Programming
    Replies: 3
    Last Post: 12th December 2006, 00: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.