Problem with getting the moment when all reply packages to my command will be received (answer end) - SSH

This is a discussion on Problem with getting the moment when all reply packages to my command will be received (answer end) - SSH ; Hello everyone, I am Delphi software developer. Since there is not open source or free classes for Delphi to implement SSH protocol in Delphi I have decided to create one based on Cryptlib Security Toolkit (by Peter Gutmann) and DelphiCryptLib ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Problem with getting the moment when all reply packages to my command will be received (answer end)

  1. Problem with getting the moment when all reply packages to my command will be received (answer end)

    Hello everyone,

    I am Delphi software developer. Since there is not open source or free
    classes for
    Delphi to implement SSH protocol in Delphi I have decided to create
    one based on
    Cryptlib Security Toolkit (by Peter Gutmann) and DelphiCryptLib
    library (by W. Gothier).

    The project is open source. The class almost finished. As a sample I
    have created
    Putty like program, of course not with all Putty functionalities but:
    it could connect
    to SSH server, send commands and receive answers.

    BUT there is still one unsolved problem. The problem is more logical
    than program,
    so that is why I thought that you can help me.

    I have no idea how can I get the moment when all reply packages to my
    command will be
    received (answer end). To make it easier to understand what I am
    speaking about lets
    see on example:

    Example: Imagine that connection to SSH server established, and we
    executes command
    'ls', the answer is very big (in size) and TSSHClient will receive
    answer data in
    few packages, for example in 5.

    Question: I am pushing data 'ls#13', and after I am popping first
    package successfully.
    Now, how I should determine that there is still 4 answer packages for
    my command (ls)?

    The first idea which came to us (some other developers taking part in
    implementing
    this class) is to wait until 'shell prompt' line will not occur in
    package (server-name#
    or user@name.com$). Later after many tests, we discover that some
    server's 'shell prompt'
    line could be just one symbol '$'. As you know symbol '$' could be
    used in file name,
    so that make possible to false 'answer end' determination.

    How this problem is solved in Putty?

    Kindest regards

    Vitali Simsive


  2. Re: Problem with getting the moment when all reply packages to mycommand will be received (answer end)

    administrator@gesoft.org wrote:
    > Now, how I should determine that there is still 4 answer packages for
    > my command (ls)?


    You can't. Even the server can't know that a command is finished.

    The good news is that you don't need to, as long as you multiplex
    between the file descriptors. That way you don't block your program if
    there are no "packets" in the stack.

    I'm not sure about a Delphi implementation, but POSIX has the select()
    and poll() system calls for that, which you might want to read up on.

    > The first idea which came to us (some other developers taking part in
    > implementing
    > this class) is to wait until 'shell prompt' line will not occur in
    > package (server-name#
    > or user@name.com$). Later after many tests, we discover that some
    > server's 'shell prompt'
    > line could be just one symbol '$'. As you know symbol '$' could be
    > used in file name,
    > so that make possible to false 'answer end' determination.


    Never rely on such things. For example, any user can set his prompt to
    an arbitrary string!

    Please see the RFCs about the SSH protocol if you want to learn more:

    http://www.snailbook.com/protocols.html

  3. Re: Problem with getting the moment when all reply packages to my command will be received (answer end)

    On Mar 5, 4:47 am, Steven Mocking
    wrote:
    > administra...@gesoft.org wrote:
    > > Now, how I should determine that there is still 4 answer packages for
    > > my command (ls)?

    >
    > You can't. Even the server can't know that a command is finished.
    >
    > The good news is that you don't need to, as long as you multiplex
    > between the file descriptors. That way you don't block your program if
    > there are no "packets" in the stack.
    >
    > I'm not sure about a Delphi implementation, but POSIX has the select()
    > and poll() system calls for that, which you might want to read up on.
    >
    > > The first idea which came to us (some other developers taking part in
    > > implementing
    > > this class) is to wait until 'shell prompt' line will not occur in
    > > package (server-name#
    > > or u...@name.com$). Later after many tests, we discover that some
    > > server's 'shell prompt'
    > > line could be just one symbol '$'. As you know symbol '$' could be
    > > used in file name,
    > > so that make possible to false 'answer end' determination.

    >
    > Never rely on such things. For example, any user can set his prompt to
    > an arbitrary string!
    >
    > Please see the RFCs about the SSH protocol if you want to learn more:
    >
    > http://www.snailbook.com/protocols.html


    Thank you very much for you post. No it is clear that it is not
    implemented in SSH protocol (answer end).

    Is there any other alternative ways to get it work? There are some
    reasons why I am trying to get the moment when command execution
    finished.

    For example: if I am performing some operations on server which takes
    log period of time I should defiantly know when it will finish, to do
    disconnect. If I will do it earlier (until command finished) its
    executions process will be stopped (I am parent of the process) and
    work will be done only partly.


  4. Re: Problem with getting the moment when all reply packages to my command will be received (answer end)

    On Mar 5, 4:47 am, Steven Mocking
    wrote:
    > administra...@gesoft.org wrote:
    > > Now, how I should determine that there is still 4 answer packages for
    > > my command (ls)?

    >
    > You can't. Even the server can't know that a command is finished.
    >
    > The good news is that you don't need to, as long as you multiplex
    > between the file descriptors. That way you don't block your program if
    > there are no "packets" in the stack.
    >
    > I'm not sure about a Delphi implementation, but POSIX has the select()
    > and poll() system calls for that, which you might want to read up on.
    >
    > > The first idea which came to us (some other developers taking part in
    > > implementing
    > > this class) is to wait until 'shell prompt' line will not occur in
    > > package (server-name#
    > > or u...@name.com$). Later after many tests, we discover that some
    > > server's 'shell prompt'
    > > line could be just one symbol '$'. As you know symbol '$' could be
    > > used in file name,
    > > so that make possible to false 'answer end' determination.

    >
    > Never rely on such things. For example, any user can set his prompt to
    > an arbitrary string!
    >
    > Please see the RFCs about the SSH protocol if you want to learn more:
    >
    > http://www.snailbook.com/protocols.html


    Thank you very much for you post. No it is clear that it is not
    implemented in SSH protocol (answer end).

    Is there any other alternative ways to get it work? There are some
    reasons why I am trying to get the moment when command execution
    finished.

    For example: if I am performing some operations on server which takes
    log period of time I should defiantly know when it will finish, to do
    disconnect. If I will do it earlier (until command finished) its
    executions process will be stopped (I am parent of the process) and
    work will be done only partly.


+ Reply to Thread