# 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.

is_login_required() -> int
  Returns non-zero if login is required before any other operations. Otherwise, zero.

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.

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 = '*', 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. 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, 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. 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. 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, 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. Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs.

check_dir(service, path, timeout = None)
  This is used to check whether a path exists or has been changed since SMB has no concept of current working directory. 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, timeout = None)
  Used to delete a path in service. The path should be a fully-qualified path (excluding the service component). Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs.

rmdir(service, path, 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). Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs.

mkdir(service, path, 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). Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs.

rename(service, old_path, new_path, 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. Raises nmb.NetBIOSTimeout if timeout (in secs) waiting for reply. Raises smb.SessionError if error occurs.

smb Module

Last modified: Mon Sep 3 21:03:31 SGT 2001