Testing ssh connection

后端 未结 2 375
别那么骄傲
别那么骄傲 2021-01-14 08:21

an important part of my project is to log in into remote server with ssh and do something with files on it:

Net::SSH.start(@host, @username, :password =>          


        
2条回答
  •  灰色年华
    2021-01-14 09:22

    Your suggested solution is similar to how I've done it before:

    Log into the local machine. For convenience you could use 'localhost' or '127.0.0.1', but for a better simulation of network activity you might want to use the full hostname. On Mac OS and Linux you can grab the host easily by using:

    `hostname`

    or

    require 'socket'
    hostname = Socket.gethostname
    

    which should be universal.

    From there create or touch a file on the local machine after logging in, so you can test for the change with your test code.

提交回复
热议问题