ne7ssh使用(ssh client)

1、准备工作

wget http://botan.randombit.net/files/Botan-1.8.8.tgz

wget http://www.cmake.org/files/v2.8/cmake-2.8.0.tar.gz

wget http://www.netsieben.com/files/ne7ssh-1.3.2.tar.gz

a、Botan安装:python configure.py; 

                      make install

                      cp libbotan.so /usr/lib 或cp libbotan.so /usr/lib64这个要看你os位数的

                       export LD_LIBRARY_PATH=/usr/lib

 

b、cmake安装:./bootstrap; make; make install

 

c、ne7ssh安装:cmake .

                         make all

                         make install

 

2、写个入门类吧

 

 

/*

*Version 0.1 by jack.wang

*

* g++ ne7ssh_test.cpp  -lnet7ssh -lbotan -o ne7sshtest

* ./ne7sshtest

**/

 

#include <ne7ssh.h>

int main(int argc,char *argv[])

{

        ne7ssh *_ssh = new ne7ssh();

        int channel1;     

        // Set SSH connection options.

        _ssh->setOptions ("aes192-cbc", "hmac-md5");

        channel1 = _ssh->connectWithPassword ("10.249.148.110", 22, "root", "hell05a");

        if (channel1 < 0)

        {

           const char *errmsg = _ssh->errors()->pop();

           if (errmsg != NULL)    

                  printf ("Connection failed with error: %s\n\n", errmsg);

           exit(-1);

        }

 

        char cmdstr[256]={0}; 

        strcat( cmdstr, "ls -ln \n" ); 

 

        if (!_ssh->send (cmdstr, channel1))

        {

             const char *errmsg = _ssh->errors()->pop(channel1);

             if (errmsg != NULL)

                 printf ("Could not send the command . error: %s.\n\n", errmsg);

              exit(-1);

        }

        // Wait for bash prompt, or die in 5 seconds

        if (!_ssh->waitFor (channel1, "0", 5))

        {

              const char *errmsg = _ssh->errors()->pop(channel1);

              if (errmsg == NULL) 

                    printf ("Timeout while waiting for remote site.error: %s.\n\n", errmsg);

              exit(-1);

        }

        const char *result;            

        result = _ssh->read (channel1);

        printf("%s\n", result);

        exit(0);

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值