- 论坛徽章:
- 30
|
本帖最后由 shijiang1130 于 2014-10-04 10:58 编辑
- -module(test_ssh).
- -compile(export_all).
- t()->
- init(),
- case ssh:connect("bbs.cu.net",22,[{inet,inet},silently_accept_hosts,{user,"root"},{password,"root"}]) of
- {ok,Ssh_connection_ref} -> io:format("Connected: ~p~n",[Ssh_connection_ref]),
- case ssh_connection:session_channel(Ssh_connection_ref,infinity) of
- {ok,ChannelId} ->
- ssh_connection:exec(Ssh_connection_ref,ChannelId,"su - test",infinity),
- loop(Ssh_connection_ref)
- end;
- {error,Reason} -> io:format("Error: ~p~n",[Reason])
- end.
- init()->
- ssh:start().
- loop(Ssh_connection_ref)->
- receive
- {ssh_cm,Ssh_connection_ref,Msg} ->
- case Msg of
- {closed,_} -> io:format("~nclosed~n");
- _-> io:format("~p~n",[Msg]),loop(Ssh_connection_ref)
- end
- end.
复制代码 |
|