Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QUrlInfo and ftp permissions
Qt 6.11 is out! See what's new in the release blog

QUrlInfo and ftp permissions

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robbin
    wrote on last edited by
    #1

    Hi everyone.

    I am working on a project (for personal use) which includes FTP client built with QFtp and Qt 4.8
    I know most of you will say that the right way to go is QNetworkAccessManager, but I found QFtp to be faster to implement.
    I am facing problems determining a file or directory permissions. According to the "docs for QUrlInfo::PermissionSpecs":http://qt-project.org/doc/qt-4.8/qurlinfo.html#PermissionSpec-enum
    @
    QUrlInfo::ReadOwner 00400 The file is readable by the owner of the file.
    QUrlInfo::WriteOwner 00200 The file is writable by the owner of the file.
    QUrlInfo::ExeOwner 00100 The file is executable by the owner of the file.
    QUrlInfo::ReadGroup 00040 The file is readable by the group.
    QUrlInfo::WriteGroup 00020 The file is writable by the group.
    QUrlInfo::ExeGroup 00010 The file is executable by the group.
    QUrlInfo::ReadOther 00004 The file is readable by anyone.
    QUrlInfo::WriteOther 00002 The file is writable by anyone.
    QUrlInfo::ExeOther 00001 The file is executable by anyone.
    @

    This means that QUrlInfo should return 777 (or 00777?) when there are full permissions, but I receive 511 instead of 777 and 493 instead of 755
    Does anyone know why I get such results? How can I test the permissions of a file or directory with QUrlInfo?
    Also, since QUrlInfo is "read only" (any changes doesn't affect the remote file or directory, only the information in the object), how can I update the permissions of the remote file or directory?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Robbin
      wrote on last edited by
      #2

      It seems the documentation isn't quite complete on this.
      I thought I'd check the values which are being returned for the enum with this:
      @
      qDebug() << QUrlInfo::ExeOwner << QUrlInfo::WriteOwner << QUrlInfo::ReadOwner;
      qDebug() << QUrlInfo::ExeGroup << QUrlInfo::WriteGroup << QUrlInfo::ReadGroup;
      qDebug() << QUrlInfo::ExeOther << QUrlInfo::WriteOther << QUrlInfo::ReadOther;
      @

      The result is:
      @
      64 128 256
      8 16 32
      1 2 4
      @

      So it's not returning the exact permissions, but it rather returns number which is probably best suited for bitwise operations. I am not quite familiar with them, but here is a simple function which actually allows me to calculate the permissions of a directory and return the result as QString:

      @
      QString MyFtpWindow::permissionsFromDecimal(uint number)
      {
      int firstbit=0, secondbit=0, thirdbit=0;
      if( number >= 256 ) {
      firstbit += 4;
      number -= 256;
      }
      if( number >= 128 ) {
      firstbit += 2;
      number -= 128;
      }

      if( number >= 64 ) {
          firstbit += 1;
          number -= 64;
      }
      
      if( number >= 32 ) {
          secondbit += 4;
          number -= 32;
      }
      
      if( number >= 16 ) {
          secondbit += 2;
          number -= 16;
      }
      
      if( number >= 8 ) {
          secondbit += 1;
          number -= 8;
      }
      
      if( number >= 4 ) {
          thirdbit += 4;
          number -= 4;
      }
      
      if( number >= 2 ) {
          thirdbit += 2;
          number -= 2;
      }
      
      if( number >= 1 ) {
          thirdbit += 1;
          number -= 1;
      }
      
      return QString("%1%2%3").arg(firstbit).arg(secondbit).arg(thirdbit);
      

      }
      @

      Certainly, not an elegant way of calculating the value, but it does work. I'll be happy if someone can provide better way of doing this. Also, I have yet to test what it would return if setuid, setgid and sticky bit are present on the file/directory being examined.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        i92guboj
        wrote on last edited by
        #3

        I know the thread is old, but since the docs are lacking a bit on this subject and I stumped on this thread, I thought I'd share my two cents.

        I do this, instead. It's similar, but it doesn't rely on the values from enum QUrlInfo::PermissionSpec having concrete values.

        @QString i92ftp::convert_perms_to_unix(int perms)
        {
        int permissions = perms;
        int first = 0;
        if(perms & QUrlInfo::ReadOwner)
        {
        permissions &= QUrlInfo::ReadOwner;
        first += 4;
        }
        if(perms & QUrlInfo::WriteOwner)
        {
        permissions &= QUrlInfo::WriteOwner;
        first += 2;
        }
        if(perms & QUrlInfo::ExeOwner)
        {
        permissions &= QUrlInfo::ExeOwner;
        first += 1;
        }

        int second = 0;
        if(perms & QUrlInfo::ReadGroup)
        {
            permissions &= QUrlInfo::ReadGroup;
            second += 4;
        }
        if(perms & QUrlInfo::WriteGroup)
        {
            permissions &= QUrlInfo::WriteGroup;
            second += 2;
        }
        if(perms & QUrlInfo::ExeGroup)
        {
            permissions &= QUrlInfo::ExeGroup;
            second += 1;
        }
        
        int third = 0;
        if(perms & QUrlInfo::ReadOther)
        {
            permissions &= QUrlInfo::ReadOther;
            third += 4;
        }
        if(perms & QUrlInfo::WriteOther)
        {
            permissions &= QUrlInfo::WriteOther;
            third += 2;
        }
        if(perms & QUrlInfo::ExeOther)
        {
            permissions &= QUrlInfo::ExeOther;
            third += 1;
        }
        
        QString permissions_str = QString("%1%2%3").arg(first).arg(second).arg(third);
        return permissions_str;
        

        }@

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved