ktbyers / scp_sidecar

Ansible modules using SCP and SSH to transfer files to network devices
Apache License 2.0
24 stars 13 forks source link

Using secure copy to import IOS #16

Open jcarte20 opened 3 years ago

jcarte20 commented 3 years ago

I am a student at ASU and I am working on my capstone project. I am trying to write a python program that will update the the Cisco IOS via netmiko. I do have ip scp server enabled on my 2960 Cisco Switch. When I run the program I get the following error code:

File "C:\Users\stscs\AppData\Local\Programs\Python\Python38\lib\site-packages\netmiko\scp_handler.py", line 360, in transfer_file self.put_file() File "C:\Users\stscs\AppData\Local\Programs\Python\Python38\lib\site-packages\netmiko\scp_handler.py", line 373, in put_file self.scp_conn.scp_transfer_file(self.source_file, destination) File "C:\Users\stscs\AppData\Local\Programs\Python\Python38\lib\site-packages\netmiko\scp_handler.py", line 46, in scp_transfer_file self.scp_client.put(source_file, dest_file) File "C:\Users\stscs\AppData\Local\Programs\Python\Python38\lib\site-packages\scp.py", line 158, in put self._recv_confirm() File "C:\Users\stscs\AppData\Local\Programs\Python\Python38\lib\site-packages\scp.py", line 363, in _recv_confirm raise SCPException(asunicode(msg[1:])) scp.SCPException: Privilege denied.

ktbyers commented 3 years ago

You need privilege level 15 access on the account you are using to SCP (direct i.e. you can't require an enable call since there is no way to do this on the Secure Copy channel).

jcarte20 commented 3 years ago

Makes sense: so I wrote the following code into my function to hopefully configure SCP: ssh = ConnectHandler(**conn) ssh.enable() ssh.send_command('aaa authentication login default local') ssh.send_command('username easypair privilege 15 password cisco') ssh.send_command('ip scp server enable')

jcarte20 commented 3 years ago

remaining code to import IOS:

transfers IOS to Cisco device and will overwrite the current IOS

    file_transfer(ssh, 
    source_file = IOS, 
    dest_file = IOS, 
    file_system = 'flash:', 
    direction = 'put', 
    disable_md5= True,
    overwrite_file = False,)
    ssh.disconnect()
    messagebox.showinfo('Info', 'Process is Complete')