pyhpecw7.features.file_copy module

Manage file transfer to HPCOM7 devices.

class pyhpecw7.features.file_copy.FileCopy(device, src, dst=None, port=22)[source]

Bases: object

This class is used to copy local files to a HPCOM7 device.

Note

SCP should first be enabled on the device.

Note

When using this class, the passed in HPCOM7 object should be constructed with the timeout equal to at least 60 seconds. Remote MD5 sum calculations can take some time.

Note

If the remote directory doesn’t exist (check remote_dir_exists), it’s the responsibility of the user to call create_remote_dir() before calling transfer_file(). Otherwise, a FileRemoteDirDoesNotExist exception will be raised.

Parameters:
  • device (HPCOM7) – connected instance of a pyhpecw7.comware.HPCOM7 object.
  • src (str) – Full path to local file to be copied.
  • dst (str) – OPTIONAL - Full path or filename of remote file. If just a filename is supplied, ‘flash:/’ will be prepended. If nothing is supplied, the source filename will be used, and ‘flash:/’ will be prepended.
  • port (int) – OPTIONAL - The SSH port over which the SCP connection is made. Defaults to 22.
device

connected instance of a pyhpecw7.comware.HPCOM7 object.

Type:HPCOM7
src

Full path to local file to be copied.

Type:str
dst

Full path of remote file.

Type:str
port

The SSH port over which the SCP connection is made.

Type:int
remote_dir_exists

Whether there remote directory exists.

Type:bool
create_remote_dir()[source]

Create the remote directory.

Raises:FileCreateDirectoryError – if the directory could not be created.
file_already_exists()[source]

Check to see if there is a remote file with the same name and md5 sum.

Returns:True if exists, False otherwise.
transfer_file(hostname=None, username=None, password=None)[source]

Transfer the file to the remote device over SCP.

Note

If any arguments are omitted, the corresponding attributes of the self.device will be used.

Parameters:
  • hostname (str) – OPTIONAL - The name or IP address of the remote device.
  • username (str) – OPTIONAL - The SSH username for the remote device.
  • password (str) – OPTIONAL - The SSH password for the remote device.
Raises: