c++ and ssh/telnet

This is a discussion on c++ and ssh/telnet within the Networking/Device Communication forums, part of the General Programming Boards category; I am trying to send commands to a server via SSH or telnet. Basically whichever is easier to accomplish at ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    89

    c++ and ssh/telnet

    I am trying to send commands to a server via SSH or telnet. Basically whichever is easier to accomplish at the moment. At my job I work with an inventory system that is text and menu based and I connect to it via telnet or ssh. I want to create a nice c++ front end to do certain tasks with and add extra functionality. My thought process thus far:

    1) Can I open ssh/telnet via c++? So far yes, ssh on a linux box. Telnet on window.

    2) Can I send actual commands to the session I open? I know it should be possible (i am sure some ssh client are written in c++) but I am not sure the best way to approach this. I am considering using piping and an external ssh client but once the connection is open how can I send a command? i.e. "2 enter" to get to option 2 of a menu.

    3) Is there a better way to send commands than in plain english? Is there a way to see thru logging or something how the server recognizes my commands? Meaning, if I am at the main menu and want option #2 I usually hit "2 enter" but I am sure the program I am working with interprets this differently. Is there a way to see how it interprets it without viewing the source?

    I know this was a lot of questions and such to ask but I am trying to get a grasp on what is possible, what is feasable, and what is within my abilities.
    Thanks

  2. #2
    n3v
    n3v is offline
    irregularly symmetrical n3v's Avatar
    Join Date
    Mar 2006
    Location
    Finland
    Posts
    67
    so let me get this straight, you're wanting to make a telnet/ssh program that has uh.. extra functions? what extra functions? all a telnet server can recognize is plain text commands, it's not like you can throw in a bunch of fancy stuff by making your own client program.

    but whatever.

    lets get to your question:

    - telnet is easier, do that first. i don't know much about ssh, but i know it's a lot more complicated

    -by using winsock, you can use telnet (and ssh) on both windows and linux (and even those 43 macintosh users around the world can too)

    -once the connection is open, sending a command varies between ssh and telnet, at least as far as i know. as i said, ssh is more complicated, but in telnet, if you type in 2, all you have to do is tell your program to send that "2" to the server. the server will recieve nothing but "2", which would execute your command, if the server was waiting for you to pick some option.

    -as for question 3, the way you send commands varies upon how the server wants you to send them. if a server sends you a list of 10 things and asks you to pick 1-10, usually simply typing a number and pressing enter will do it. if the server asks for your name though, you'll have to send what it wants before you can move on. it depends totally on how the server is programmed.

    do you have any ideas on where you're going to start on this program? do you know winsock?
    If you make a man a fire,
    he will be warm for a day.
    If you set a man on fire,
    he will be warm for the rest of his life.

  3. #3
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    As n3v said, you could look into sockets and write a basic telnet program. Telnet is a simple protocol, and fairly easy to understand. (SSH is harder.)

    Piping input to a Putty window would be hard. I'm not sure that genuine pipes can be used - Putty is a GUI application. At best, you might be able to simulate keypresses. Piping would probably be much easier under a console or in Linux.

    And are you sure you have permission to do such things? Make sure that your actions (creating software that can talk to company software) doesn't violate any agreements with your company and doesn't anger your boss.

    EDIT: And don't cross post between the boards.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    89
    The extra functionality I spoke of only refers to working with the current server. Currently if I want to remove 100 products it either has to be done by hand, or I have now started writing WinBatch scripts to do it but that solution is not quite as elegant and tight as I would like.

    There is a console based putty client that can be piped into.

    As far as permission, the reason I have to do it like this in the first place is because the admin of the server wont let my depertment design real software to work on the system. The software we are using is very old and combersome and to do basic tasks that would be easy in modern databases is extremely tedious. However, as far as just talking to the server and doing the same tasks I would normally do just through a program instead of by hand is completely acceptable. My boss actually wants me to start working on this as kind of a side project to make things like adding/removing products easier for new people we hire in. I am not really changing anything just wanting to put it all into a nice GUI.

    Thanks for the replies. I am not familiar with winsock but have been reading about it and other forms of communication. I just wanted to be set on the right path before I started putting a bunch of work into the wrong thing. If winsock is what I should be using to do this now I know that and can focus on it.

    Sorry about the cross posting I just wasnt sure which forum this question would be applicable in.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21