I need to login to a device (CISCO Switch) using SSH and retrieve the configuration.
I've tried to use plink for this based on the information I've found here :
http://www.purebasic.fr/english/viewtop ... 13&t=53356
So I need to do 4 steps:
1.Connect to the device with username and password (I think that this works...)
2.After connected : Answer a question with "no" in order to skip a "WARNING - POTENTIAL SECURITY BREACH!" warning.
3.send a command ("sh run") to the device that lists the current configuration
4.save the result (output) to a string
So here is what I do manually:
Code: Select all
plink -ssh -l admin -pw 123 10.1.6.100
WARNING - POTENTIAL SECURITY BREACH!
The server's host key does not match the one PuTTY has
cached in the registry....
If you want to carry on connecting but without updating
the cache, enter "n".
Update cached key? (y/n) : n <--- how to send this "n" ? (I will add the host key, but for now I want to understand how I could answer the question with "no")
Using username "admin".
.
**********Logged in: SYSTEM01**************************************
.
IDESWB7b#sh run <---- how to send this "sh run" command ?
Building configuration...
Current configuration : 20130 bytes <---- save this output (maybe 100 lines...)
!
! Last configuration change at 16:42:30 CEST Wed Aug 20 2014 by cancom
! NVRAM config last updated at 16:42:32 CEST Wed Aug 20 2014 by cancom
!
version 12.2
vlan 2000
--More-- ^C
.....
I have the following code that should just send "no" to answer the question, but it fails showing "exit code: 1"
thank you#PLinkPath$ = #DQUOTE$ + "C:\Programme\putty 0.63\plink.exe" + #DQUOTE$
#Server$ = "10.1.6.100"
#User$ = "admin"
#Password$ ="123"
sCommand.s = "-ssh -l " + #User$ + " -pw " + #Password$ + " " + #Server$
PLinkID = RunProgram(#PLinkPath$, sCommand,"", #PB_Program_Open|#PB_Program_Read|#PB_Program_Write)
Output$ = ""
If PLinkID
;delay (1000)
WriteProgramStringN (PLinkID,"n") ; Try to send "n"+CR$
While ProgramRunning(PLinkID)
If AvailableProgramOutput(PLinkID)
Debug ReadProgramString(PLinkID) + Chr(13)
Output$ + ReadProgramString(PLinkID) + Chr(13)
EndIf
Wend
Output$ + Chr(13) + Chr(13)
Output$ + "Exitcode: " + Str(ProgramExitCode(PLinkID))
CloseProgram(PLinkID) ; Close the connection to the program
else
MessageRequester("Error", "Erro")
EndIf
MessageRequester("Output", Output$)