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:
objectThis class is used to copy local files to a
HPCOM7device.Note
SCP should first be enabled on the device.
Note
When using this class, the passed in
HPCOM7object should be constructed with thetimeoutequal 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 callcreate_remote_dir()before callingtransfer_file(). Otherwise, aFileRemoteDirDoesNotExistexception will be raised.Parameters: - device (HPCOM7) – connected instance of
a
pyhpecw7.comware.HPCOM7object. - 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.
-
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: Trueif exists,Falseotherwise.
-
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.devicewill 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: - FileTransferError – if an error occurs during the file transfer.
- FileHashMismatchError – if the source and destination hashes don’t match.
- FileNotReadableError – if the local file doesn’t exist or isn’t readable.
- FileNotEnoughSpaceError – if there isn’t enough space on the device.
- FileRemoteDirDoesNotExist – if the remote directory doesn’t exist.
- device (HPCOM7) – connected instance of
a