I'm using the Pederosa.Terminal Control but I didn't figure out how to send commands directly from c# code.
Is possible to share an example to how to programatically send commands (ex. "ls-la" or other) and wait for result ?
Last edit: Francisco Marques 2019-04-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm using the Pederosa.Terminal Control but I didn't figure out how to send commands directly from c# code.
Is possible to share an example to how to programatically send commands (ex. "ls-la" or other) and wait for result ?
Last edit: Francisco Marques 2019-04-30
function ssh_connect() {
var loopcnt = 0;
var param = new SSHTerminalParam( ConnectionMethod.SSH2, host, account, password);
param.Caption = title+host_name;
param.Encoding = EncodingType.UTF8; // SJIS ???? EncodingType.SHIFT_JIS
param.TerminalType = "VT100";
param.AuthType = AuthType.Password;
var c = env.Connections.Open(param);
r = c.ReceiveData();
while(r.indexOf(passwait1)==-1 && r.indexOf(passwait2)==-1 && r.indexOf(passwait3)==-1 && r.indexOf(account+"@")==-1 && loopcnt r = c.ReceiveData(); //waiting prompt for account;
loopcnt++;
}
if(supassword!==""){
if(loopcnt c.TransmitLn("su -");
loopcnt=0;
}
r = c.ReceiveData();
while(r.indexOf(passwait1)==-1 && r.indexOf(passwait2)==-1 && r.indexOf(passwait3)==-1 && loopcnt r = c.ReceiveData(); //waiting prompt for password
loopcnt++;
}
if(loopcnt c.TransmitLn(supassword);
}
}
var text = "";
var buff = host+"\r\n";
var fso = new ActiveXObject("Scripting.FileSystemObject");
if(fso.FileExists(filename)){
var f = fso.OpenTextFile(filename,1);//1:ForReading
while(!f.AtEndOfStream){
text = f.ReadLine();
if(text!==host){
buff += text+"\r\n";
}
}
f.close();
var f = fso.OpenTextFile(filename,2,true);//2:ForWriting
f.write(buff);
f.close();
}
}