Results 1 to 8 of 8

Thread: Winsock and ssh

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    4

    Winsock and ssh

    Hey guys

    Bit of a problem I have

    Anyone ever written code in vb to ssh to a server(an ssh client)

    If so would be great to talk I have got as far as getting the diffie-hellman response from the ssh server but cant seem to find out what to send back to it

    Any idea's would be great

    Cheers

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Winsock and ssh

    VB what, VB6 or VB.NET?

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    4

    Re: Winsock and ssh

    Hi

    VB6 I am using now, but have .net also so dont mind which one

    Cheers

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Winsock and ssh

    Normally one uses an existing SSH client to establish a tunnel to an SSH server. Then your "Winsock" program talks through the tunnel to some server at the SSH host (or behind it), without any special knowledge of SSH.

    PuTTY or PLink are the usual clients.

    So I assume you plan to implement tunnelling and port forwarding? Or are you just trying to make an SSH Shell connection?

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    4

    Re: Winsock and ssh

    What I would like to do is ssh to a linux box, run some commands, parse the ouput and display the results.

    I would like this accross ssh as I have to do this for multiple servers and I cannot write sockets for linux.

    I have written this program previously for telnet and now need ssh, we cannot enable telnet for security issues...

  6. #6
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Winsock and ssh

    I haven't seen any free or cheap SSH client components, and I can't believe it is worth the trouble to create this functionality from scratch.

    Considering your low volume of use I'm not sure it was worth writing Telnet logic to do this sort of thing. There are a few Telnet components out there (though not many free ones), however once again since your needs are modest I'd offer the same solution I'll propose now - it handles both Telnet and SSH.


    The native "glue" and automation technology in VB is COM of course. A secondary "glue" or IPC mechanism VBers often default to is TCP/IP, mostly because of the nice Winsock control we got from Microsoft. A much better "glue" for use within one computer though (if you can't use COM) is explicit tasking and Anonymous Pipes.

    Tasking and Pipes puts us into the realm of the hackish Unix world of course. It's about all they have to work with in a normal Unix installation. While it works slightly differently in Windows the idea is the same though:

    Fire off a utility as a secondary process and "automate" it (remotely control it) via standard I/O redirection through pipes.


    Since Microsoft didn't expect us to be doing this in VB they never provided a handy tool like the Winsock control. All we got was the marginally useful Shell() function.

    From here we all take a different approach. Some moan that Microsoft, VB, etc. are "no good bums" while others of us roll up our sleeves and deal with it. The result is that many of us have our own pet code for handling this. I haven't seen any standard emerge, and I have a couple of code fragments for this myself.


    So where am I going with this?

    I believe that PLink is your friend here. It was designed to be automated via scripts anyway, and handles Telnet and SSH shell sessions. All you need is a way to do this from a VB program. I have two solutions, one a bit clunkier than the other.

    The first one is older, and uses a class called CExec to do the work. CExec is slightly more tailored toward automating PLink, but is based on blocking calls and is generally a less finished product.

    The second one is newer and a little more polished, using a user control called ShellPipe. This is of more general use in automating a "command line utility" and uses an async approach with events. It is a lot more like the Winsock control, and if you've used the Winsock control properly in the past (no goofy looping with DoEvents() calls) you should be comfortable with it pretty quickly.


    I won't do your homework for you, but I can attach sample projects that contain each of these options. The PLClient example was purpose-built to show how to use PLink as a path to a data server on a remote machine. It expects PLink.exe to be in the program's current directory when run, and while it uses Telnet it could be changed to use SSH with a tiny command line parameter change.

    The ShellPipe Demos examples show how ShellPipe might be used for general automation tasks. It would be easy to use ShellPipe to create a program that automates PLink, and I suspect this is the better way to go. I never use CExec any more myself.


    Oh, you can get PLink at PuTTY Download Page.

    I think you'll find this a lot less work than trying to create an SSH client from scratch.
    Attached Files Attached Files

  7. #7
    New Member
    Join Date
    Jun 2007
    Posts
    4

    Re: Winsock and ssh

    you might want to take a look at SSH Factory for .NET

    http://www.jscape.com/sshfactorydotnet/

    They have a SshSession class that makes it easy to automate execution of commands on remote SSH server.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Winsock and ssh

    Quote Originally Posted by vglass
    They have a SshSession class that makes it easy to automate execution of commands on remote SSH server.
    Did you write it yourself?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width