مشکل دوم حل شد، ظاهرا برای کامندی که از طریق ssh میزنم باید یک چنل دیگه درست بشه.
Program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
Uses
System.SysUtils,
System.StrUtils,
Ssh;
Var
Ssh: HCkSsh;
cmdOutput: PWideChar;
success: Boolean;
port: Integer;
host: PWideChar;
channelNum: Integer;
Begin
Ssh := nil;
Try
Ssh := CkSsh_Create();
success := CkSsh_UnlockComponent(Ssh, 's2yjlR.CB10750_Ig3zlV2R4C77');
If (success <> True) Then
Begin
Raise Exception.Create(CkSsh__lastErrorText(Ssh));
End;
port := ****;
host := '192.168.185.254';
success := CkSsh_Connect(Ssh, host, port);
If (success <> True) Then
Begin
Raise Exception.Create(CkSsh__lastErrorText(Ssh));
End;
CkSsh_putIdleTimeoutMs(Ssh, 5000);
success := CkSsh_AuthenticatePw(Ssh, '*****', '******');
If (success <> True) Then
Begin
Raise Exception.Create(CkSsh__lastErrorText(Ssh));
End;
channelNum := CkSsh_OpenSessionChannel(Ssh);
If (channelNum < 0) Then
Begin
Raise Exception.Create(CkSsh__lastErrorText(Ssh));
End;
While True Do
Begin
success := CkSsh_SendReqExec(Ssh, channelNum, 'system resource print');
If (success <> True) Then
Begin
Raise Exception.Create(CkSsh__lastErrorText(Ssh));
End;
success := CkSsh_ChannelReceiveToClose(Ssh, channelNum);
If (success <> True) Then
Begin
Raise Exception.Create(CkSsh__lastErrorText(Ssh));
End;
cmdOutput := CkSsh__getReceivedText(Ssh, channelNum, 'ansi');
If (CkSsh_getLastMethodSuccess(Ssh) <> True) Then
Begin
Raise Exception.Create(CkSsh__lastErrorText(Ssh));
End;
Writeln(Trim(LeftStr(cmdOutput, Pos(#10, cmdOutput))));
Sleep(3000);
channelNum := CkSsh_OpenSessionChannel(Ssh);
If (channelNum < 0) Then
Begin
Raise Exception.Create(CkSsh__lastErrorText(Ssh));
End;
End;
Except
On E: Exception Do
Begin
CkSsh_Disconnect(Ssh);
CkSsh_Dispose(Ssh);
Writeln('Exception class name = ' + E.ClassName);
Writeln('Exception Message = ' + E.Message);
Readln;
End;
End;
End.