How to use the netmiko.FileTransfer function in netmiko

To help you get started, we’ve selected a few netmiko examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ktbyers / scp_sidecar / ansible_modules / cisco_file_transfer.py View on Github external
'username': module.params['username'],
        'password': module.params['password'],
        'port': int(module.params['port']),
        'verbose': False,
    }

    ssh_conn = ConnectHandler(**net_device)
    source_file = module.params['source_file']
    dest_file = module.params['dest_file']
    dest_file_system = module.params['dest_file_system']
    enable_scp = module.boolean(module.params['enable_scp'])
    overwrite = module.boolean(module.params['overwrite'])
    check_mode = module.check_mode
    scp_changed = False

    with FileTransfer(ssh_conn, source_file, dest_file, file_system=dest_file_system) as scp_transfer:

        # Check if file already exists and has correct MD5
        if scp_transfer.check_file_exists() and scp_transfer.compare_md5():
            module.exit_json(msg="File exists and has correct MD5", changed=False)

        if not overwrite and scp_transfer.check_file_exists():
            module.fail_json(msg="File already exists and overwrite set to false")

        if check_mode:
            if not scp_transfer.verify_space_available():
                module.fail_json(msg="Insufficient space available on remote device")

            module.exit_json(msg="Check mode: file would be changed on the remote device",
                             changed=True)

        # Verify space available on remote file system
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
def _xfer_file(
        self,
        source_file=None,
        source_config=None,
        dest_file=None,
        file_system=None,
        TransferClass=FileTransfer,
    ):
        """Transfer file to remote device.

        By default, this will use Secure Copy if self.inline_transfer is set, then will use
        Netmiko InlineTransfer method to transfer inline using either SSH or telnet (plus TCL
        onbox).

        Return (status, msg)
        status = boolean
        msg = details on what happened
        """
        if not source_file and not source_config:
            raise ValueError("File source not specified for transfer.")
        if not dest_file or not file_system:
            raise ValueError("Destination file or file system not specified.")
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
def _xfer_file(self, source_file=None, source_config=None, dest_file=None, file_system=None,
                   TransferClass=FileTransfer):
        """Transfer file to remote device.

        By default, this will use Secure Copy if self.inline_transfer is set, then will use
        Netmiko InlineTransfer method to transfer inline using either SSH or telnet (plus TCL
        onbox).

        Return (status, msg)
        status = boolean
        msg = details on what happened
        """
        if not source_file and not source_config:
            raise ValueError("File source not specified for transfer.")
        if not dest_file or not file_system:
            raise ValueError("Destination file or file system not specified.")

        if source_file:
github austind / iosfw / iosfw / iosfw.py View on Github external
the image, the class is still useful for checking image
            existence, free space, etc.

        """
        if src_file is None:
            src_file = self.upgrade_image_src_path
        if dest_file is None:
            dest_file = self._get_dest_path(absolute=False)
        if self.transport == "ssh":
            ft_args = {
                "ssh_conn": self.device,
                "source_file": src_file,
                "dest_file": self._get_dest_path(dest_file, absolute=False),
                "file_system": self.dest_filesystem,
            }
            self.ft = FileTransfer(**ft_args)
        elif self.transport == "telnet":
            self.ft = None
            raise NotImplementedError
        else:
            raise ValueError("Transport must be ssh or telnet.")
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
def _scp_file(self, source_file, dest_file, file_system):
        """
        SCP file to remote device.

        Return (status, msg)
        status = boolean
        msg = details on what happened
        """
        return self._xfer_file(
            source_file=source_file,
            dest_file=dest_file,
            file_system=file_system,
            TransferClass=FileTransfer,
        )
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
def _scp_file(self, source_file, dest_file, file_system):
        """
        SCP file to remote device.

        Return (status, msg)
        status = boolean
        msg = details on what happened
        """
        return self._xfer_file(
            source_file=source_file,
            dest_file=dest_file,
            file_system=file_system,
            TransferClass=FileTransfer,
        )
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
def _scp_file(self, source_file, dest_file, file_system):
        """
        SCP file to remote device.

        Return (status, msg)
        status = boolean
        msg = details on what happened
        """
        return self._xfer_file(source_file=source_file, dest_file=dest_file,
                               file_system=file_system, TransferClass=FileTransfer)
github napalm-automation / napalm / napalm / ios / ios.py View on Github external
def _xfer_file(self, source_file=None, source_config=None, dest_file=None, file_system=None,
                   TransferClass=FileTransfer):
        """Transfer file to remote device.

        By default, this will use Secure Copy if self.inline_transfer is set, then will use
        Netmiko InlineTransfer method to transfer inline using either SSH or telnet (plus TCL
        onbox).

        Return (status, msg)
        status = boolean
        msg = details on what happened
        """
        if not source_file and not source_config:
            raise ValueError("File source not specified for transfer.")
        if not dest_file or not file_system:
            raise ValueError("Destination file or file system not specified.")

        if source_file: