erlang实现ssh

借鉴自http://blog.youkuaiyun.com/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").

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值