def _rm(self, path):
     if _share_has_path(path):
         wpath = _as_unc_path(self.host, path)
         stats = smbclient.stat(wpath)
         if S_ISDIR(stats.st_mode):
             smbclient.rmdir(wpath)
         else:
             smbclient.remove(wpath)
Beispiel #2
0
def smb_rmdir(client: SMBClient, args: dict):
    hostname = args.get('hostname')
    username = args.get('username')
    password = args.get('password')
    path = handle_path(args.get('path'))
    path = os.path.join(hostname or client.hostname, path)

    client.create_session(hostname, username, password)
    rmdir(path)

    return f"Directory: {path} was removed successfully"
Beispiel #3
0
 def rmdir(self, path):
     return smbclient.rmdir(self._join_path(path), **self._conn_kwargs)
 def rmdir(self, path):
     if _share_has_path(path):
         wpath = _as_unc_path(self.host, path)
         smbclient.rmdir(wpath)
from smbclient import (
    listdir,
    mkdir,
    register_session,
    rmdir,
    scandir,
)

# Optional - register the server with explicit credentials
register_session("server", username="******", password="******")

# Create a directory (only the first request needs credentials)
mkdir(r"\\server\share\directory", username="******", password="******")

# Remove a directory
rmdir(r"\\server\share\directory")

# List the files/directories inside a dir
for filename in listdir(r"\\server\share\directory"):
    print(filename)

# Use scandir as a more efficient directory listing as it already contains info like stat and attributes.
for file_info in scandir(r"\\server\share\directory"):
    file_inode = file_info.inode()
    if file_info.is_file():
        print("File: %s %d" % (file_info.name, file_inode))
    elif file_info.is_dir():
        print("Dir: %s %d" % (file_info.name, file_inode))
    else:
        print("Symlink: %s %d" % (file_info.name, file_inode))