omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Python SMB Connection

    Pythonista
    3
    85
    24568
    Loading More Posts
    • 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.
    • DavinE
      DavinE last edited by

      Hey Guys,

      I have a Problem and i don't find my solution...
      Here's my test Code:

      import smb
      from smb.SMBConnection import SMBConnection
      from nmb.NetBIOS import NetBIOS
      
      netbios = NetBIOS()
      
      share_name          = "share"
      user_name           = "user"
      password            = "passwd"
      server_IP           = "xxx.xxx.xxx.251"
      local_machine_name  = socket.gethostname()
      server_machine_name = netbios.queryIPForName(server_IP)
      
      print(server_machine_name[0])
      
      # create and establish connection
      conn = SMBConnection(user_name, password, local_machine_name, server_machine_name[0], domain="WORKGROUP", use_ntlm_v2=True)
      # 139
      # 445
      print(conn.connect(server_IP, 445))
      

      i get every Time this Message:

      ELEKTROTECHNIK
      False
      

      but the Function conn.connect return on Success True... not False....
      i Have no idea what i'm doing wrong...

      im trying to connect to my Synology NAS 718

      i hope you guys know what im doing wrong....

      Thanks!!

      cvp 2 Replies Last reply Reply Quote 0
      • cvp
        cvp @DavinE last edited by

        @DavinE I always use it with port=139 on my Western Digital NAS.

        1 Reply Last reply Reply Quote 0
        • cvp
          cvp @DavinE last edited by

          @DavinE said:

          local_machine_name = socket.gethostname()

          Try

          local_machine_name  = socket.gethostname()[0]
          
          1 Reply Last reply Reply Quote 0
          • DavinE
            DavinE last edited by

            @cvp i tried both :( same result...

            cvp 1 Reply Last reply Reply Quote 0
            • cvp
              cvp @DavinE last edited by cvp

              @DavinE said:

              server_machine_name = netbios.queryIPForName(server_IP)

              Sorry, error😢 , try

              server_machine_name = netbios.queryIPForName(server_IP)[0]
              
              DavinE 1 Reply Last reply Reply Quote 0
              • DavinE
                DavinE @cvp last edited by

                @cvp said:

                @DavinE said:

                server_machine_name = netbios.queryIPForName(server_IP)

                Sorry, error😢 , try

                server_machine_name = netbios.queryIPForName(server_IP)[0]
                

                @cvp, no :(
                i want to cry ^^

                cvp 1 Reply Last reply Reply Quote 0
                • cvp
                  cvp @DavinE last edited by

                  @DavinE said:

                  i want to cry ^^

                  Sorry, I don't understand, that will say that this does not work?

                  1 Reply Last reply Reply Quote 0
                  • DavinE
                    DavinE last edited by DavinE

                    @cvp
                    yes, sorry :(

                    I used both ports

                    cvp 1 Reply Last reply Reply Quote 0
                    • cvp
                      cvp @DavinE last edited by

                      @DavinE strange, I use this successfully

                      			ip = bios.queryName(self.smb_name)
                      			return ip[0]
                      
                      DavinE 1 Reply Last reply Reply Quote 0
                      • DavinE
                        DavinE @cvp last edited by

                        @cvp said:

                        @DavinE strange, I use this successfully

                        			ip = bios.queryName(self.smb_name)
                        			return ip[0]
                        

                        in your case whats the self.smb_name? Server Name ?

                        cvp 2 Replies Last reply Reply Quote 0
                        • cvp
                          cvp @DavinE last edited by

                          @DavinE sorry, a mistake more,

                          			bios = NetBIOS()
                          			srv_name = bios.queryIPForName(remote_smb_ip, timeout=timeout)
                          			return srv_name[0]
                          
                          1 Reply Last reply Reply Quote 0
                          • DavinE
                            DavinE last edited by

                            @cvp
                            hmm...
                            I get the same output as i get with my code ELEKTROTECHNIK

                            cvp 1 Reply Last reply Reply Quote 0
                            • cvp
                              cvp @DavinE last edited by

                              @DavinE said:

                              in your case whats the self.smb_name? Server Name

                              Yes

                              DavinE 1 Reply Last reply Reply Quote 0
                              • cvp
                                cvp @DavinE last edited by

                                @DavinE said:

                                local_machine_name = socket.gethostname()
                                server_machine_name = netbios.queryIPForName(server_IP)

                                Did you try with

                                local_machine_name  = socket.gethostname()[0]
                                server_machine_name = netbios.queryIPForName(server_IP)[0]
                                
                                DavinE 1 Reply Last reply Reply Quote 0
                                • DavinE
                                  DavinE @cvp last edited by

                                  @cvp said:

                                  @DavinE said:

                                  in your case whats the self.smb_name? Server Name

                                  Yes

                                  When i use your code above

                                  ip = bios.queryName(self.smb_name)
                                              return ip[0]
                                  

                                  server_machine_name = netbios.queryIPForName(server_IP)[0]

                                  print(server_machine_name) ELEKTROTECHNIK
                                  print(local_machine_name) Davin
                                  print(netbios.queryName(server_machine_name)) and here None

                                  why none ?

                                  1 Reply Last reply Reply Quote 0
                                  • DavinE
                                    DavinE @cvp last edited by DavinE

                                    @cvp said:

                                    @DavinE said:

                                    local_machine_name = socket.gethostname()
                                    server_machine_name = netbios.queryIPForName(server_IP)

                                    Did you try with

                                    local_machine_name  = socket.gethostname()[0]
                                    server_machine_name = netbios.queryIPForName(server_IP)[0]
                                    

                                    This did not work here i get only the first letter

                                    local_machine_name = socket.gethostname()[0]

                                    in my case D

                                    cvp 1 Reply Last reply Reply Quote 0
                                    • cvp
                                      cvp @DavinE last edited by

                                      @DavinE could you try with my module
                                      SMB_client.py

                                      and

                                      from SMB_client import SMB_client
                                      
                                      my_smb = SMB_client(username='admin',password='admin',smb_name='share')
                                      my_smb.connect()
                                      
                                      tree = my_smb.getRemoteTree()
                                      for elem in tree:
                                      	print(elem)
                                      
                                      DavinE 1 Reply Last reply Reply Quote 0
                                      • DavinE
                                        DavinE @cvp last edited by

                                        @cvp said:

                                        @DavinE could you try with my module
                                        SMB_client.py

                                        and

                                        from SMB_client import SMB_client
                                        
                                        my_smb = SMB_client(username='admin',password='admin',smb_name='share')
                                        my_smb.connect()
                                        
                                        tree = my_smb.getRemoteTree()
                                        for elem in tree:
                                        	print(elem)
                                        

                                        yeah i tried it but i can retry it...

                                        i do not have SMB_client installed
                                        should i install it ? and try

                                        cvp 2 Replies Last reply Reply Quote 0
                                        • cvp
                                          cvp @DavinE last edited by

                                          @DavinE did you see the link in my post?

                                          DavinE 1 Reply Last reply Reply Quote 0
                                          • cvp
                                            cvp @DavinE last edited by

                                            @DavinE said:

                                            should i install it ? and try

                                            Sure

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors