I have written an Erlang application to send data over SSH. After sending ssh_connection:send, I asynchronously wait for the response by calling receive
function. But, the receive
function is timing out. I have tried with a higher timeout value of 2 minutes as well. What is wrong with my code? Please help me in debugging the issue.
I have debugged the issue as follows;
-
I checked the packets exchanged using Wireshark. I see packets in Wireshark for all steps performed by my Erlang application (namely
ssh:connect, ssh_connection:session_channel & ssh_connection:send
). -
I have enabled
dbg
for relevant modules. I see debug logs in the Erlang shell for the stepsssh:connect, ssh_connection:session_channel
. But, not forssh_connection:sen
d
application: start(ssh).
crypto:start().
ssh:start().
%% Creation of SSH connection
{ok, Client} = ssh:connect("10.0.2.15", 2022, [{user, "admin"}, {password, "admin"}]).
%% Creation of SSH Channel
{ok, Channel} = ssh_connection:session_channel(Client, 30000).
NetconfMessage = <<"<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n<capabilities>\n<capability>urn:ietf:params:netconf:base:1.0</capability>\n</capabilities>\n</hello>\n">>.
%% Sending data over the SSH Channel
case ssh_connection:send(Client, Channel, NetconfMessage) of
ok ->
io:format("Netconf message sent successfully ~n"),
%% Asynchronously wait for the response
receive
{ssh, Channel, Data} ->
io:format("Received data: ~s~n", [Data])
after 60000 ->
io:format("Timeout receiving data.~n")
end;
{error, Reason} ->
io:format("Error sending Netconf message: ~p~n", [Reason])
end.
%% Closing the SSH connection
ssh:close(Client).