EldoS | Feel safer!

Software components for data protection, secure storage and transfer

TElSimpleSSHClient v6.1

Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.
#15126
Posted: 11/25/2010 08:01:23
by Janos Tovabbito (Basic support level)
Joined: 11/25/2010
Posts: 6

hi
I need to den data to the standard input of the command.
The situation is:
My side: windows, SecureBlackBox Simple SSH Client
Other side: SunOs, very limited functionalities system.

I have 2 types of commands:
Simple command: Send a command and receive answer (which is text or binary). It works:
Code
s2.Command = "Something";
Console.WriteLine( "Open nd execute Command" );
s2.Open();

Console.WriteLine( "Wait for answer" );
while (!s2.CanReceive( 0 ) && (s2.Active) )
{
}
Int32 i = 1;
MemoryStream str = new MemoryStream();

Console.WriteLine( "Is Active?" + s2.Active.ToString() );
Console.WriteLine( "ExitStatus:" + s2.ExitStatus.ToString() );

while (i > 0)
{

    Byte[] buffer = new Byte[ 1024 ];
    i = s2.ReceiveData( buffer, 0, 1024, true );
    if (i != 0)
    {
        str.Write( buffer, 0, i ); // add to stream
    }
}
str.Seek( 0, SeekOrigin.Begin );
Byte[] result = new Byte[ str.Length ];
i = str.Read( result, 0, (Int32)str.Length );
Console.WriteLine( "Answer:" + Encoding.ASCII.GetString( result ) );

s2.Close();


the other commands wait for a binary file (ZIP, DAT etc) on its StandardInput.
like as
SSH.EXE -i ... -l ... SaveIt FarSideName.zip <MyFile.Zip
I can do this with Chilkat in tihs way:
Code
Console.WriteLine( "Send command" );
success = ssh.SendReqExec( channelNum, cmd );
Console.WriteLine( "Send data" );
success = ssh.ChannelSendData( channelNum, fileContent );
Console.WriteLine( "EOF sent" );
success = ssh.ChannelSendEof( channelNum );

i try this in same way in SBB:
Code
s2.Command = "SomethingElse";
Console.WriteLine( "Open and execute Command" );
s2.Open();
Console.WriteLine( "SendFile" );
s2.SendData( TheFile );

Console.WriteLine( "Wait for answer" );
while (!s2.CanReceive( 0 ) && (s2.Active) )
{
}
Int32 i = 1;
MemoryStream str = new MemoryStream();

Console.WriteLine( "Is Active?" + s2.Active.ToString() );
Console.WriteLine( "ExitStatus:" + s2.ExitStatus.ToString() );

while (i > 0)
{

    Byte[] buffer = new Byte[ 1024 ];
    i = s2.ReceiveData( buffer, 0, 1024, true );
    if (i != 0)
    {
        str.Write( buffer, 0, i ); // add to stream
    }
}
str.Seek( 0, SeekOrigin.Begin );
Byte[] result = new Byte[ str.Length ];
i = str.Read( result, 0, (Int32)str.Length );
Console.WriteLine( "Answer:" + Encoding.ASCII.GetString( result ) );

s2.Close();


in this way, the file not uploaded and no answer received, but no error msg or exception.
How can send dta to StdIn of the command?
Terminal is not working! It is a very limited connection!
#15127
Posted: 11/25/2010 08:29:00
by Eugene Mayevski (EldoS Corp.)

If you have a license, please assign the license ticket to your user account before we continue. The ticket itself and the procedure of its use are specified in the registration e-mail that was sent to you upon license purchase.

If you don't have a license, please download and install SecureBlackbox 8.1, which is the latest version.


Sincerely yours
Eugene Mayevski
#15165
Posted: 11/30/2010 07:31:12
by Janos Tovabbito (Basic support level)
Joined: 11/25/2010
Posts: 6

hi

i downloaeded the 8.1

(SBUtils.Unit.SetLicenseKey( "81E859A1826B6AE23F30FE755D3962B.......)

but my problem is not solved by the new version.
Code
            // try to simulate this : addFile -s skk/ig fel2inp.zip <SSHChannel_As_StdIn";
            // this addFile command wait the file on Its StdIn and Its StdIn is rediceted to SSHChannel

            s2.Command = "addFile -s skk/ig fel2inp.zip";

            Byte[] TheFile = File.ReadAllBytes( "fel.zip" );

            Console.WriteLine( "Open and execute Command" );
            s2.Open();
            Console.WriteLine( "Can Receive....");
            s2.CanReceive( 0 );
            Console.WriteLine( "SendFile" );
            s2.SendData( TheFile );
            Console.WriteLine( "Wait for answer..." );
            while (!s2.CanReceive( 0 ) && (s2.Active))
            {
            }

            Int32 i = 1;
            MemoryStream str = new MemoryStream();

            Console.WriteLine( "Is Active? " + s2.Active.ToString() );
            Console.WriteLine( "Is CanReceive? " + s2.CanReceive( 0 ).ToString() );
            Console.WriteLine( "ExitStatus: " + s2.ExitStatus.ToString() );

            while (i > 0)
            {

                Byte[] buffer = new Byte[ 1024 ];
                i = s2.ReceiveData( buffer, 0, 1024, true );
                if (i != 0)
                {
                    str.Write( buffer, 0, i ); // add to stream
                }
            }
            str.Seek( 0, SeekOrigin.Begin );
            Byte[] result = new Byte[ str.Length ];
            i = str.Read( result, 0, (Int32) str.Length );
            Console.WriteLine( "Answer:" + Encoding.ASCII.GetString( result ) );

            s2.Close();


the result is:
Open and execute Command
s2_OnKeyValidate:SBSSHKeyStorage.TElSSHKey
s2_OnAuthenticationSuccess SBSimpleSSH.TElSimpleSSHClient
s2_OnSendCommandRequest SBSimpleSSH.TElSimpleSSHClient cmd:addFile -s skk/ig fel2inp.zip
Can Receive....
SendFile
Wait for answer...
s2_OnCloseConnection
Is Active? False
Is CanReceive? True
ExitStatus: 131
Answer:/mnt/disk/data/Client/bin/ssh_command.sh: line 48: 576 Quit
(core dumped) $command

s2_OnCloseConnection
**** FINISHED ****

the OnSend and OnReceive handlers are not fired.
the file not uploaded.
ho can i send something to StdInput?
#15168
Posted: 11/30/2010 08:25:27
by Eugene Mayevski (EldoS Corp.)

OnSend and OnReceive handlers have nothing to do at all with your problem - they are used when you use custom socket as a transport.

You need to check the server side to find out why it doesn't accept the data that you send. I guess that the script is waiting for some signal that would tell the server that the data transfer is complete. The code related to Chilkat says that some EOF is sent. You can try sending EOF using SendData("\0x0D\0x0A"). However the question arises what would happen if your binary file has EOF as well.

Also try setting RequestTerminal property to true or false and see if this changes anything.


Sincerely yours
Eugene Mayevski
#15176
Posted: 12/01/2010 02:23:37
by Janos Tovabbito (Basic support level)
Joined: 11/25/2010
Posts: 6

ok.
i send EOF (try with 0x0D 0x0A (CRLF) and with 0x1A (^Z) too)

if RequestTerminal = true (default)
then addFile do nothing anser is same as abowe

if RequestTerminal = false
then addFile received the file and saved it to server disk!
BUT no answerm the
Console.WriteLine( "Wait for answer..." );
while (!s2.CanReceive( 0 ) && (s2.Active))
{
}

loop never finished. If i jump out from this loop after 1-2 minutes and try read data from channel, (s2.ReceiveData( buffer, 0, 1024, true ) ) the answer is empty, which is not good. addFile send an answer on successful upload (send back de md5 hasf of the file)

i can't do anything on the server. It is a virtual machine and i can't login into this server. it is a BlackBox with a specified interface (like as addFile)
#15177
Posted: 12/01/2010 02:37:30
by Janos Tovabbito (Basic support level)
Joined: 11/25/2010
Posts: 6

hi

if i use s2.SendEOF(); then it works!
file created and answer recevied, if s2.RequestTerminal = false;
but in this case the loop never ending but i need to wait for answer.
how can i do this? (Thread.Sleep is not the best solution :) )
#15178
Posted: 12/01/2010 02:44:33
by Eugene Mayevski (EldoS Corp.)

If you receive the answer, you can just close connection (as you know the size of the reply).


Sincerely yours
Eugene Mayevski
#15179
Posted: 12/01/2010 02:49:52
by Janos Tovabbito (Basic support level)
Joined: 11/25/2010
Posts: 6

uhhit works, something happened on VM, i restarted it and now it works, the loop exit ven answer received.

thank's for Your help!
the solution was:

set s2.RequestTerminal = false;
and use s2.SendEOF();
#15184
Posted: 12/02/2010 01:45:06
by Janos Tovabbito (Basic support level)
Joined: 11/25/2010
Posts: 6

hi

i try to simulate some errors.
Load RSA ey from file, but file name is worng, this file doesn't exists.
i nor give any exception when load a non-existing file IsKeyValid() is TRUE!
when i try open SSH then give an error (connection lost 10058)
but this error msg is not too informative (what is the problem? 10058 its is a code and i can't find what is it mean....)

How can i handle problems? (write the correct error reason, catch the problems etc)
(sshSimpleClient.OnError is not fired)

TElSSHKey key = new TElSSHKey();
key.KeyFormat = TSBSSHKeyFormat.kfOpenSSH;
key.LoadPrivateKey( "nothing.pem", "" );
if (!key.IsKeyValid())
{
Logger.LogError( "Key invalid" );
}
#15185
Posted: 12/02/2010 01:55:17
by Vsevolod Ievgiienko (EldoS Corp.)

Hello.

TElSSHKey.LoadPrivateKey returns error codes. The list of error codes is available here http://eldos.com/documentation/sbb/do...tekey.html

The code can look like this:

Code
int errCode = key.LoadPrivateKey( "nothing.pem", "" );
switch (errCode) {
  case SB_ERROR_SSH_KEYS_INVALID_PUBLIC_KEY:
    Logger.LogError("error ...");
    break;
  ...
}
Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.

Reply

Statistics

Topic viewed 2638 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!