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. How to send/receive a file from samba shared folder?

How to send/receive a file from samba shared folder?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 2.3k Views
  • 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.
  • M Offline
    M Offline
    MarKS
    wrote on 18 Apr 2021, 18:01 last edited by
    #1

    Consider me a newbie in Qt network programming. I have a simple UI where I select a file from my local PC and when I click on Send button I would like to send the file over to the samba shared folder.

    I know the IP address and the port number I would like to connect to. But I am completely confused about what do I need to send the file. Do I need a Server and Client? Or QTcpSocket would be enough? No idea.

    Any pointers to links or examples are appreciated.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 18 Apr 2021, 18:18 last edited by
      #2

      Hi,

      The usual way to do that is to mount the Samba share on your machine and use it like any other network drive. Then you can use QFile to copy the file over to it.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply 18 Apr 2021, 21:35
      2
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 18 Apr 2021, 19:37 last edited by
        #3

        Hi
        Just as a note.
        There is also smbclient if on a Linux OS. it can copy files to a share.
        https://www.linuxjournal.com/content/smbclient-security-windows-printing-and-file-transfer

        1 Reply Last reply
        1
        • S SGaist
          18 Apr 2021, 18:18

          Hi,

          The usual way to do that is to mount the Samba share on your machine and use it like any other network drive. Then you can use QFile to copy the file over to it.

          M Offline
          M Offline
          MarKS
          wrote on 18 Apr 2021, 21:35 last edited by MarKS
          #4

          @SGaist I forgot to mention my app is supposed to work on Win 10. Do I still need to mount the samba share explicitly? Or does windows have native support to access share folders?

          K 1 Reply Last reply 19 Apr 2021, 00:44
          0
          • M MarKS
            18 Apr 2021, 21:35

            @SGaist I forgot to mention my app is supposed to work on Win 10. Do I still need to mount the samba share explicitly? Or does windows have native support to access share folders?

            K Offline
            K Offline
            Kent-Dorfman
            wrote on 19 Apr 2021, 00:44 last edited by
            #5

            @MarKS said in How to send/receive a file from samba shared folder?:

            I forgot to mention my app is supposed to work on Win 10. Do I still need to mount the samba share explicitly? Or does windows have native support to access share folders?

            I don't believe Qt does, whether win10 can or not. If it's a file then transport it as a file to a mounted share. You probably don't want to write a Qt specific samba smb/cifs client class.

            this <https://stackoverflow.com/questions/25298946/qt-is-there-a-class-for-shared-folders> may have useful information. First result in google search. LOL

            M 1 Reply Last reply 19 Apr 2021, 06:45
            0
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 19 Apr 2021, 05:57 last edited by
              #6

              Hi
              Windows understand SMB so if the share is set up correctly

              You can use the
              copy command

              copy file.txt \\ip_or_hostname\sharename
              

              However, if the user needed for the shares, is different from the current login user in windows, it will
              need to use runas which will not allow you to send a password as a parameter.

              In such cases,
              you can use
              net use x:\ip_or_hostname\sharename /user:username password

              Do note that the newest win 10 uses smb3 (protocol version) and will also use v2 on demand but for version smb1 it has to be enabled.
              If a newer Linux box it uses smb3 pr default. only something to notice with an older Linux box.

              M 1 Reply Last reply 19 Apr 2021, 06:45
              3
              • K Kent-Dorfman
                19 Apr 2021, 00:44

                @MarKS said in How to send/receive a file from samba shared folder?:

                I forgot to mention my app is supposed to work on Win 10. Do I still need to mount the samba share explicitly? Or does windows have native support to access share folders?

                I don't believe Qt does, whether win10 can or not. If it's a file then transport it as a file to a mounted share. You probably don't want to write a Qt specific samba smb/cifs client class.

                this <https://stackoverflow.com/questions/25298946/qt-is-there-a-class-for-shared-folders> may have useful information. First result in google search. LOL

                M Offline
                M Offline
                MarKS
                wrote on 19 Apr 2021, 06:45 last edited by
                #7

                @Kent-Dorfman My bad. I have been through those links but it is already 7 yrs old. Thought there might be improvements to it.

                1 Reply Last reply
                0
                • M mrjj
                  19 Apr 2021, 05:57

                  Hi
                  Windows understand SMB so if the share is set up correctly

                  You can use the
                  copy command

                  copy file.txt \\ip_or_hostname\sharename
                  

                  However, if the user needed for the shares, is different from the current login user in windows, it will
                  need to use runas which will not allow you to send a password as a parameter.

                  In such cases,
                  you can use
                  net use x:\ip_or_hostname\sharename /user:username password

                  Do note that the newest win 10 uses smb3 (protocol version) and will also use v2 on demand but for version smb1 it has to be enabled.
                  If a newer Linux box it uses smb3 pr default. only something to notice with an older Linux box.

                  M Offline
                  M Offline
                  MarKS
                  wrote on 19 Apr 2021, 06:45 last edited by
                  #8

                  @mrjj This is very resourceful and informative. I got my answer. Thanks!

                  1 Reply Last reply
                  0

                  7/8

                  19 Apr 2021, 06:45

                  • Login

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