scp_example.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python
  2. '''
  3. Cisco IOS only
  4. Requires scp https://github.com/jbardin/scp.py
  5. '''
  6. from netmiko import ConnectHandler, SCPConn
  7. from SECRET_DEVICE_CREDS import cisco_881
  8. def main():
  9. '''
  10. SCP transfer cisco_logging.txt to network device
  11. Use ssh_conn as ssh channel into network device
  12. scp_conn must be closed after file transfer
  13. '''
  14. ssh_conn = ConnectHandler(**cisco_881)
  15. scp_conn = SCPConn(ssh_conn)
  16. s_file = 'cisco_logging.txt'
  17. d_file = 'cisco_logging.txt'
  18. print "\n\n"
  19. scp_conn.scp_transfer_file(s_file, d_file)
  20. scp_conn.close()
  21. output = ssh_conn.send_command("show flash: | inc cisco_logging")
  22. print ">> " + output + '\n'
  23. # Disable file copy confirmation
  24. output = ssh_conn.send_config_set(["file prompt quiet"])
  25. # Execute config merge
  26. print "Performing config merge\n"
  27. output = ssh_conn.send_command("copy flash:cisco_logging.txt running-config")
  28. # Verify change
  29. print "Verifying logging buffer change"
  30. output = ssh_conn.send_command("show run | inc logging buffer")
  31. print ">> " + output + '\n'
  32. # Restore copy confirmation
  33. output = ssh_conn.send_config_set(["file prompt alert"])
  34. if __name__ == "__main__":
  35. main()