# smb.SMB Objects

A smb.SMB object can be created using the following constructor.

SMB(remote_name, remote_host, my_name = None, host_type = nmb.TYPE_SERVER, sess_port = nmb.NETBIOS_SESSION_PORT)
  Setup a SMB connection between 2 NetBIOS names, my_name and remote_name. If my_name is not supplied, a suitable name will be generated. Note that some machines might reject the connection if remote_name does not belong to their machines. remote_host should be a string containing the hostname or IP address of the remote machine. host_type specifies the type of the remote host.

smb.SMB objects have the following methods.

get_server_os() -> string
  Returns the OS of the SMB server

get_server_lanman() -> string
  Returns the LAN manager name of the SMB server

get_server_domain() -> string
  Returns the domain name of the SMB server

is_login_required() -> int
  Returns non-zero if login is required before any other operations. Otherwise, zero. Note that public services and services which are in share mode are still visible even if login is not performed. However, services which are in user mode are disallowed.

login(name, password, domain = '', timeout = None)
  Login into the remote machine using name and password. Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs during login or login fails. Note that this login procedure only logins into user-shared services. For services which are in share mode, refer to the specific file operations for more details.

list_shared(timeout = None) -> [ <smb.SharedDevice instance> ... ]
  Returns a list of smb.SharedDevice instances containing the shared devices/services. Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs.

list_path(service, path = '*', password = None, timeout = None) -> [ <smb.SharedFile instance> ... ]
  Returns a list of smb.SharedFile instances containing the shared files in the path. service is shared name returned in the list_shared() call. password is the authentication info required for access if this service is in share mode and is protected. Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs.

retr_file(service, filename, callback, mode = SMB_O_OPEN, offset = 0, password = None, timeout = None)
  Retrieve a file of filename in service and writes the content using the callback function. filename should be a fully-qualified path name of the file (excluding the service component). offset is used to indicate the offset to start reading the file. password is the authentication info required for access if this service is in share mode and is protected. The callback function should be able to take a string argument which is the data read from the remote file. Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs.

stor_file(service, filename, callback, mode = SMB_O_CREAT | SMB_O_TRUNC, offset = 0, timeout = None)
  Store a file of filename in service by reading from the callback function. filename should be a fully-qualified path name of the file (excluding the service component). offset is used to indicate where to start writing. password is the authentication info required for access if this service is in share mode and is protected. The callback function should be able to take an int argument which indicates how many bytes to return as the file data. Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs.

copy(src_service, src_path, dest_service, dest_path, callback = None, write_mode = SMB_O_CREAT | SMB_O_TRUNC, src_password = None, dest_password = None, timeout = None)
  Copy a file of src_path in src_service to dest_path in dest_service. Both src_path and dest_path should be a fully-qualified path name of the file (excluding the service component). The callback function should be able to take in 2 int arguments which are the number of bytes copied and the total number of bytes to copy respectively. src_password and dest_password are the authentication info required for access if the src_service and/or dest_service are in share mode and are protected. Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs.

check_dir(service, path, password = None, timeout = None)
  This is used to check whether a path exists or has been changed since SMB has no concept of current working directory. password is the authentication info required for access if this service is in share mode and is protected. Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if path does not exist or an error has occurred.

remove(service, path, password = None, timeout = None)
  Used to delete a path in service. The path should be a fully-qualified path (excluding the service component). password is the authentication info required for access if this service is in share mode and is protected. Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs.

rmdir(service, path, password = None, timeout = None)
  Used to delete a directory in service. The directory must be empty for the operation to work. The path should be a fully-qualified path (excluding the service component). password is the authentication info required for access if this service is in share mode and is protected. Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs.

mkdir(service, path, password = None, timeout = None)
  Create a directory of path in service. The path must not have existed and should be a fully-qualified path (excluding the service component). password is the authentication info required for access if this service is in share mode and is protected. Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs.

rename(service, old_path, new_path, password = None, timeout = None)
  Rename a file of old_path to new_path in service. Both old_path and new_path must be a fully-qualified path (excluding the service component) and new_path must not exist. password is the authentication info required for access if this service is in share mode and is protected. Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs.

browse_domains(timeout = None) -> [ <string instance> ... ]
  Return a list of string containing the available domain names. Note that the remote host must be at least a Domain Master Browse Server for this operation to succeed. Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs.

browse_servers_for_domain(timeout = None) -> [ <smb.SMBMachine instance> ... ]
  Return a list of smb.SMBMachine instances containing the information about the registered SMB servers for the domain. Note that the remote machine has to be at least a Master Browse Server for this operation to succeed. Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs.

smb Module

Last modified on Sat, Apr 27 2002