2016-11-21 84 views
0

如何設置連接到ssh服務器的超時時間節點js在ssh2中設置ssh的超時時間

目前,我連接到服務器用下面的代碼:

var Client = require('ssh2'); 

var conn = new Client(); 
conn.on('ready', function(){ 
    console.log("connected"); 
}); 
conn.on('error', function(){ 
    console.log("fails"); 
}); 
conn.connect({ 
    host: ip, 
    port: 22, 
    username: user, 
    password: password 
}); 

回答

1

您可以設置readyTimeoutconnect選項是這樣的:

conn.connect({ 
    host: ip, 
    port: 22, 
    username: user, 
    password: password, 
    readyTimeout: 5000 
}); 

這將取消任何連接,是不是準備在5秒內。

您可以在documentation of ssh2中瞭解更多關於它的信息。

+0

非常感謝你,我沒有看到readytimeout config – beginerdeveloper