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:
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 :)
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--