Link to home
Start Free TrialLog in
Avatar of jack jones
jack jones

asked on

Not able to copy tftp to device using python

Please review below code, not able to copy config from device to tftp and vice versa
import paramiko
ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect('192.168.1.12', port=22, username='cisco', password='cisco')

stdin, stdout, stderr = ssh.exec_command('copy tftp: flash: ')

stdin.write('192.168.1.10')

stdin.write('\n')

stdin.flush()

stdin.write('demotesting')
stdin.write('\n')
stdin.flush()

stdin.write('dest_demo')
stdin.write('\n')

output = stdout.readlines()
print '\n'.join(output)
ssh.close()

Open in new window


error :

L
ine has invalid autocommand "copy tftp: flash: "

Open in new window

Avatar of Craig Beck
Craig Beck
Flag of United Kingdom of Great Britain and Northern Ireland image

Why not just put the whole copy command on one line, instead of trying to write special characters?

stdin, stdout, stderr = ssh.exec_command("copy tftp://192.168.1.10/folder/file.ext flash:")

Open in new window


Also, have you trusted 192.168.1.10's SSH key on the remote device first?
Avatar of jack jones
jack jones

ASKER

from remote device im able to ping 192.168.1.10 that is my tftp  also when i command directly from router its getting successful copied to tftp
changes the script to below it gives error
Line has invalid autocommand "copy tftp://192.168.1.10/TFTP-Root/file.ext flash:"

import paramiko
ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect('192.168.1.12', port=22, username='cisco', password='cisco')

stdin, stdout, stderr = ssh.exec_command("copy tftp://192.168.1.10/TFTP-Root/file.ext flash:")





output = stdout.readlines()
print '\n'.join(output)
ssh.close()

Open in new window

Are you using "login local" authentication on the VTY lines, or are you using aaa authentication?
we are using login local for authentication
Try using aaa instead. I'm sure I remember a bug which affects autocommands when using login local.
can u pls send the modification m confused...
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.