Python Forum
Netmiko timing out after sending command
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Netmiko timing out after sending command
#1
The purpose of my script is to connect to our FTD (Firepower threat defence) and run a packet capture then ftp it to a host

The problem:

The script works as it it transfers the file, but it then times out and I can't figure out why, I would leave it but I need to continue the script to analyse the caputre.

Any help apprecaited

Here is the output from the FTD if I were typing the commands:

Output:
> file copy 192.168.1.10 myusername / capture.pcap Enter password for [email protected]:<myPassword> Copying capture.pcap Copy successful. Copying capture.pcap Copy successful. Copying capture.pcap Copy successful. >
This is an excerpt from my code:
#--snip--
output += connection.send_command(
    'file copy 192.168.1.10 myusername / capture.pcap',
    expect_string=r'password'
)
print('sending ftp password')
output += connection.send_command(
    'c7bernet',
    expect_string=r'>'
)
#--snip--
And the error message:
Error:
Traceback (most recent call last): File "C:\Users\awarren\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\channel.py", line 699, in recv out = self.in_buffer.read(nbytes, self.timeout) File "C:\Users\awarren\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\buffered_pipe.py", line 164, in read raise PipeTimeout() paramiko.buffered_pipe.PipeTimeout During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\awarren\AppData\Local\Programs\Python\Python37\lib\site-packages\netmiko\base_connection.py", line 541, in _read_channel_expect new_data = self.remote_conn.recv(MAX_BUFFER) File "C:\Users\awarren\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\channel.py", line 701, in recv raise socket.timeout() socket.timeout During handling of the above exception, another exception occurred: Traceback (most recent call last): File "fmcCaptureSendVdi.py", line 35, in <module> expect_string=r'>' File "C:\Users\awarren\AppData\Local\Programs\Python\Python37\lib\site-packages\netmiko\base_connection.py", line 1366, in send_command new_data = self.read_until_pattern(pattern=re.escape(cmd)) File "C:\Users\awarren\AppData\Local\Programs\Python\Python37\lib\site-packages\netmiko\base_connection.py", line 618, in read_until_pattern return self._read_channel_expect(*args, **kwargs) File "C:\Users\awarren\AppData\Local\Programs\Python\Python37\lib\site-packages\netmiko\base_connection.py", line 552, in _read_channel_expect "Timed-out reading channel, data not available." netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available.

Sorry, I solved my own problem.. I used this bit of code from here: Netmiko Github

I think it explains itself but basically looks at the output from the command slightly differently - if anyone can elaborate I'd be grateful :)

#--snip--
command = "file copy 192.168.1.10 myusername / capture.pcap"
print(connection.find_prompt())
output = connection.send_command_timing(command)
if "password" in output:
    output += connection.send_command_timing(
        "<password>", strip_prompt=False, strip_command=False
    )
#--snip--
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  netmiko: print out specific line matches with 'Cisco IOS Software' in sh ver output sabrina 1 3,359 Nov-28-2022, 10:05 AM
Last Post: carstenlp
  Netmiko Program ssh from the Jumpssh ( host -> Jumphost -> Network Device matya0403 3 6,770 Jul-31-2020, 08:22 AM
Last Post: dtw
  Connect to device without paramiko/netmiko modules kang18 3 3,000 Jun-05-2020, 10:54 AM
Last Post: Larz60+
  netmiko connecting to arista devices. dan1962 0 4,070 Feb-07-2020, 09:23 PM
Last Post: dan1962

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020