Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Notes on Python smbclient for Samba
- #more notes https://github.com/jborean93/smbprotocol/blob/master/examples/high-level/file-management.py
- #install
- sudo apt-get install gcc python-dev libkrb5-dev python-pip
- pip install smbprotocol[kerberos]
- #useage
- import os,smbclient
- server="192.168.1.101"
- user="username"
- password="password"
- folder="folder"
- #login
- smbclient.register_session(server, username=user, password=password)
- #list option
- dir(smbclient)
- #mkdir
- smbclient.mkdir(r"\\\\"+server+"\\"+folder+"\\newdir")
- #remove dir
- smbclient.removedirs(r"\\\\"+server+"\\"+folder+"\\newdir")
- #list dir
- smbclient.listdir(r"\\\\"+server+"\\"+folder)
- #scan directory
- d=smbclient.scandir(r"\\\\"+server+"\\"+folder)
- for item in d:
- print(item)
- #write to file
- with smbclient.open_file(r"\\\\"+server+"\\"+folder+"\\scan.txt",mode="w") as fd:
- fd.write(u"scan")
- #read a file
- with smbclient.open_file(r"\\\\"+server+"\\"+folder+"\\scan.txt",mode="rb") as fd:
- fd.read()
Add Comment
Please, Sign In to add comment