Connect to a linux server using ssh in ruby

Source: Internet
Author: User
1 require 'net/ssh'
2 require 'net/sftp'
3
4 host = hostip
5 username = username
6 password = password
7
8 #~ # Display files and system versions
9 server_cmd1 = 'LS-l'
10 server_cmd2 = 'cat/etc/issue'
11
12 # Install the following components
13 # gem install net-ssh
14 # gem install net-sftp
15
16
17 Net: SSH. start (host, username,: password => password) do | ssh |
18 puts ssh.exe c! (Server_cmd1)
19 puts ssh.exe c! (Server_cmd2)
20
21
22 ssh. sftp. connect do | sftp |
23 Dir. foreach ('.') do | file |
24 puts file
25 end
26 end
27 end

 

 

Article: http://www.infoq.com/cn/articles/ruby-file-upload-ssh-intro

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.