Netmiko FileTransfer与python

时间:2018-12-07 21:01:44

标签: python python-3.x cisco cisco-ios

我正在研究一个脚本,以使用netmiko FileTransfer将某些文件传输到Cisco IOS设备。以下是我发现完成此操作的代码。但是我似乎无法找到source_file应该在哪里或如何指定文件在主机上的位置。如何指定从何处复制该文件?

dest_file_system = 'disk0:/'
source_file = 'test1.txt' # where should this file be live?
dest_file = 'test1.txt'

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

if not scp_transfer.check_file_exists():
   if not scp_transfer.verify_space_available():
      raise ValueError("Insufficient space available on remote device")

        print("\nTransferring file\n")
        scp_transfer.transfer_file()

1 个答案:

答案 0 :(得分:1)

从脚本角度看,如果您只是想按名称调用源文件,则该源文件应与脚本本身位于同一目录中。如果要将文件移动到新目录,则脚本中的搜索路径相对于脚本运行的目录。示例1-file_name.txt与脚本位于同一目录中在脚本中,只需调用文件source =“ file_name.txt”。示例2在保存脚本的当前目录中创建test_folder并将其命名为test_folder将file_name.txt移到test_folder中。在脚本中,您的源变量不需要看起来像此源=“ test_folder / file_name.txt”