erlang实现ssh

借鉴自http://blog.csdn.net/the__one/article/details/6567443http://blog.yufeng.info/archives/1509 

单命令启动

ct_run -shell -logdir ./logs -config ./sshdemo.config

交互模式启动

%%ct是common_test模块的缩写
ct:install([{config,"/Users/mmc/Projects/erlang/ct_demo/sshdemo.config"}]). ct:start_interactive().

看看对不对

ct:get_config(sshdemo).

sshdemo.config

{sshdemo,
     [
     {ssh, "192.168.1.110"},
     {port, 22},
     {user, "mmc"},
     {password, "12345"}
     ]
}.

sftp相关,读写文件

{ok, CH}=ct_ssh:connect(sshdemo, sftp).
ct_ssh:write_file(CH, "/tmp/sshdemo/test.dat", "hello").
ct_ssh:read_file(CH, "/tmp/sshdemo/test.dat").

ssh相关,执行命令

{ok, CH1}=ct_ssh:connect(sshdemo, ssh).
ct_ssh:exec(CH1, "cp /tmp/sshdemo/test.dat /tmp/sshdemo/test1.dat").

感觉还有很多有意思的功能,可以挖掘一下

原文地址:https://www.cnblogs.com/ziyouchutuwenwu/p/4872845.html