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
    24339
    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.
    • cvp
      cvp @DavinE last edited by

      @DavinE this should be ok if you know the ip but not the smb name

      ip = ....
      my_smb = SMB_client()
      smb_name = my_smb.getBIOSName(ip)
      print(smb_name)
      
      my_smb = SMB_client(username=user,password=pwd, smb_name=smb_name, print_errors=False)
      my_smb.connect()
      
      smb_files = my_smb.getRemoteDir('', '*')
      for smb_file in smb_files:
      	smb_filename = smb_file.filename
      	print(smb_file.filename)
      
      DavinE 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @DavinE last edited by

        @DavinE said:

        sry.... i'm confused..

        I'm too, forget all except my just previous post

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

          @cvp said:

          @DavinE this should be ok if you know the ip but not the smb name

          print(smb_name)
          

          This is: ELEKTROTECHNIK
          i think that's correct!

          smb_files = my_smb.getRemoteDir('', '*')
          print(smb_files)
          

          Here i get None

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

            @DavinE said:

            Here i get None

            I you used my last post, that would say the ip is not correct.
            The first my_smb is used to get the smb_name from the ip and the second uses the smb_name.

            I print the smb_name, do you see it?

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

              Now, this should work if you know the ip

              from SMB_client import SMB_client
              
              ip = 'xxx.xxx.xxx.xxx'
              user = 'xxxxxx'
              pwd = 'xxxxx'
              my_smb = SMB_client()
              smb_name = my_smb.getBIOSName(ip)
              print('smb_name=',smb_name)
              my_smb = SMB_client(username=user,password=pwd, smb_name=smb_name, print_errors=False)
              my_smb.connect()
              smb_files = my_smb.getRemoteDir('', '*')
              for smb_file in smb_files:
              	smb_filename = smb_file.filename
              	print(smb_file.filename)
              
              DavinE 1 Reply Last reply Reply Quote 0
              • DavinE
                DavinE @cvp last edited by

                @cvp said:

                Now, this should work if you know the ip

                from SMB_client import SMB_client
                
                ip = 'xxx.xxx.xxx.xxx'
                user = 'xxxxxx'
                pwd = 'xxxxx'
                my_smb = SMB_client()
                smb_name = my_smb.getBIOSName(ip)
                print('smb_name=',smb_name)
                my_smb = SMB_client(username=user,password=pwd, smb_name=smb_name, print_errors=False)
                my_smb.connect()
                smb_files = my_smb.getRemoteDir('', '*')
                for smb_file in smb_files:
                	smb_filename = smb_file.filename
                	print(smb_file.filename)
                

                so i tried it with my Raspberry Pi2....
                here is my output:

                pi@RaspberryPi2:~/TEST/smb $ python smb_de.py 
                ('smb_name=', 'ELEKTROTECHNIK')
                .
                ..
                Drive
                

                on my iPad pro 12.9" i get only:

                smb_name=, ELEKTROTECHNIK
                

                with the same user and pwd....
                this is a iPad problem or ?

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

                  @cvp said:

                  my_smb = SMB_client()
                  smb_name = my_smb.getBIOSName(ip)
                  print('smb_name=',smb_name)

                  These lines do not use user nor pwd, it is only to get the smb_name that you need to use in tHe second. Note that if you know this smb_name, the ip is not necessary

                  my_smb = SMB_client(username=user,password=pwd, smb_name=smb_name, print_errors=False)
                  my_smb.connect()
                  smb_files = my_smb.getRemoteDir('', '*')
                  for smb_file in smb_files:
                  	smb_filename = smb_file.filename
                  	print(smb_file.filename)
                  
                  1 Reply Last reply Reply Quote 0
                  • cvp
                    cvp @DavinE last edited by

                    @DavinE said:

                    pi@RaspberryPi2:~/TEST/smb $ python smb_de.py

                    This line is printed by the smb client, and it is not the same on iPad, it does not print anything, it is normal.

                    But is the connection ok?

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

                      @cvp ,

                      this is my test code for my connection:

                      import smb, socket
                      from smb.SMBConnection import SMBConnection
                      from nmb.NetBIOS import NetBIOS
                      
                      netbios = NetBIOS()
                      
                      user = 'xxx'
                      pwd = 'xxx'
                      
                      share_name          = "ELEKTROTECHNIK"
                      user_name           = user
                      password            = pwd
                      server_IP           = "xxx.xxx.178.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, 139))
                      

                      on my iPad i get here False

                      on my Raspi2 i get True.....

                      or need i to "translate" my Pwd on my iPad in Base64 ?

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

                        @DavinE said:

                        or need i to "translate" my Pwd on my iPad in Base24 ?

                        No.

                        Did you retry with the other port? 445

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

                          @cvp
                          yes, its the same False

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

                            @DavinE you cold also remove ,use_ntlm_v2 = True) in the source code of SmB_client.py

                            Just to check

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

                              @cvp
                              Its the same...

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

                                @cvp

                                Do you know what protocol Pythonista use ?
                                SMB1; SMB2; SMB3 ?

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

                                  @DavinE no idea.
                                  Your code works on my NAS

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

                                    @cvp
                                    Which on do you have ? WD or ?

                                    and do you mean on your iPad ?

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

                                      @DavinE my NAS is a WD
                                      I work on an iPad. WitH your code.
                                      It also works with a flash drive connected in usb slot of my router, drive that I always reach in smb.

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

                                        Obviously, the smb module in Pythonista is old and is not identical as on your Radpberry.

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

                                          @cvp said:

                                          @DavinE my NAS is a WD
                                          I work on an iPad. WitH your code.
                                          It also works with a flash drive connected in usb slot of my router, drive that I always reach in smb.

                                          When i use my Raspi with the data i get this:

                                          RASPBERRYPI4
                                          Error on line 87 OperationFailure Failed to list  on Ebner-Elektrotechnik: Unable to connect to shared device
                                          ==================== SMB Message 0 ====================
                                          SMB Header:
                                          -----------
                                          Command: 0x03 (SMB2_COM_TREE_CONNECT) 
                                          Status: 0x00000000 
                                          Flags: 0x00 
                                          PID: 1563 
                                          MID: 9 
                                          TID: 0 
                                          Data: 78 bytes 
                                          b'09000000480046005c005c005200410053005000420045005200520059005000490034005c00450062006e00650072002d0045006c0065006b00740072006f0074006500630068006e0069006b00' 
                                          SMB Data Packet (hex):
                                          ----------------------
                                          b'fe534d42400000000000000003000000000000000000000009000000000000001b06000000000000979d8799000000000000000000000000000000000000000009000000480046005c005c005200410053005000420045005200520059005000490034005c00450062006e00650072002d0045006c0065006b00740072006f0074006500630068006e0069006b00'
                                          ==================== SMB Message 1 ====================
                                          SMB Header:
                                          -----------
                                          Command: 0x03 (SMB2_COM_TREE_CONNECT) 
                                          Status: 0xC0000022 
                                          Flags: 0x01 
                                          PID: 1563 
                                          MID: 9 
                                          TID: 0 
                                          Data: 9 bytes 
                                          b'090000000000000000' 
                                          SMB Data Packet (hex):
                                          ----------------------
                                          b'fe534d4240000000220000c003000100010000000000000009000000000000001b06000000000000979d87990000000000000000000000000000000000000000090000000000000000'
                                          
                                          []
                                          

                                          this is a shared folder on my Pi Ebner-Elektrotechnik

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

                                            @cvp said:

                                            Obviously, the smb module in Pythonista is old and is not identical as on your Radpberry.

                                            it looks so but it sucks.... :(

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