How to send commands to putty - putty

I'm writing a simple executable in C that needs to open a putty session and send commands to it, then close putty. I can open/close the putty session (i'm not that bad) but i'm not too sure on how to send putty the commands.
Any ideas??

From the PuTTY FAQ:
How can I use PuTTY to make an SSH
connection from within another
program?
Probably your best bet is to use
Plink, the command-line connection
tool. If you can start Plink as a
second Windows process, and arrange
for your primary process to be able to
send data to the Plink process, and
receive data from it, through pipes,
then you should be able to make SSH
connections from your program.
This is what CVS for Windows does, for
example.
Plink can use PuTTY's saved sessions in addition to opening sites directly.
PLink's options are documented in Chapter 7 of the PuTTY manual.

Use the DLL, Luke. http://www.winputty.com/

Have you looked at the source for QuickPutty? It's LGPL licensed.

Related

How would I create an SFTP connection if my application framework does not contain an API for it?

I am trying to connect to an SFTP server with my AIR application. It doesn't matter that it's an AIR application except that I haven't found any libraries or AIR API methods for it.
My first thought is to find a library in another language and rewrite it in ActionScript. I'd rather not do that and my lack of experience may introduce security issues.
My second thought is to call a native process or command such as sftp or sshpass or curl from my main application and pass the local and remote upload locations to it and let it do the work. The downside to this is if they don't have the command installed they have to install a separate program.
My questions are:
Are these SFTP commands available by default on both Mac and Windows?
Should I store the users login (I do not want to) or prompt them to enter it each time? Does SFTP / public key remove the need for that?
I've found two related questions here and here but some of it is over my head. They also seem to be specific to *nux (which may work for Mac as well but not Windows).
I do not have the experience in this area so I would welcome those with experience to give guidance if this is a good idea or not. Overview type answers are welcome for me as I can attempt to work out the details. If no answer is given, once I've figured it out I'll post an answer. Please do not close this question (rather suggest edits).
FYI I'm using AIR to make a native process call.
An AIR application in the extended desktop profile can execute a file,
as if it were invoked by the command line. It can communicate with the
standard streams of the native process. Standard streams include the
standard input stream (stdin), the output stream (stdout), the
standard error stream (stderr).
I can also create and call a scpt, sh or bat file.
Commands installed on my Mac:
curl_init(), curl_setopt()
ssh
sftp
Commands not installed on my Mac:
sshpass
Are these SFTP commands available by default on both Mac and Windows?
No. There is no sftp nor ssh on windows by default, unless you install it through cygwin or bundle them in your application (also solution).
Should I store the users login (I do not want to) or prompt them to enter it each time?
Prompt is preferred.
Does SFTP / public key remove the need for that?
Yes, but you will have to store private key, which is almost the same like storing password.

connecting to a computer in LAN and send cmd commands

I need to connect to a computer in LAN
and to open CMD in the remote computer
and send a command (for example ping www.google.com - but other commands..)
I thought to open a server on the remote computer and a client in my computer and every time to send a command as a string to the server side, and to send that command to the cmd (i know it's easy with c++)
is there another way to do this?
is there a way in vb6 to open cmd in a remote computer and to send a command?
the reason i write this here is because the client side will be written in vb6
the client is not written, but i will put it in a program written in vb6
thank you
You might be able to use WMI. You could copy over a batch file, script or an executable and then use WMI to execute it remotely.
You can use Win32_Process.Create as described here: Creating Processes Remotely
You could use Psexec from SysInternals and avoid writing anything for the server side.
You could also use telnet/ssh.

I'm having trouble using SCP to upload files to Sourceforge

So I finished writing my first program and I'm trying to upload it to my sourceforge account, but the file size is to big to use the normal html5 upload manager sourceforge provides. Soursceforge says "For larger files, use FTP, SCP, or rsync". They also provided this page for references of what to commands to send via the command line like this one, which I had no idea how to use
scp file.zip jsmith#frs.sourceforge.net:/home/frs/project/fooproject/Rel_1
Should I be able to run this through the WinSCP.com prompt like so?
WinSCP> scp file.zip jsmith#frs.sourceforge.net:/home/frs/project/fooproject/Rel_1
Seeing as how the commandline kicked my but (I'm totally open to learning how to use the commandline for file transfer to sourceforge if you have any links to any tutorials, this one was too difficult to understand with all the broken English :/ ), I tried creating a connection with the WinSCP GUI and the following info
Host: myusername#frs.sourceforge.net
Username: MyUsername
Password: MyPassword
but I get the following error before the SCP connection is finished
Connection has been unexpectedly closed. Server sent command exist
status 1.
Error skipping startup message. Your shell is probably incompatible
with the application (bash is recommended).
Any help or a nudge in the right direction would be greatly appreciated. From what I've gathered I should learn more about shells, but I have no idea where to begin. Thanks in advance and cheers!
You are using SCP protocol with WinSCP. Make sure you use SFTP.
It appears that you're trying to do something weird with WinSCP. You're trying the "Open Terminal" option, which, I think just tries to open an ssh session at the host. But, we don't support ssh sessions to the frs.sourceforge.net
Normally, if you try to ssh to that host, you get this message:
Welcome!
This is a restricted Shell Account.
You can only copy files to/from here.
Connection to frs.sourceforge.net closed.
But I think WinSCP eats that, or something.
Anyway, I think what you need to do is just use WinSCP as a graphical two-pane sftp client. Navigate to the file to upload on the left, and to the destination directory on the right, etc.
In general, the best place to ask this kind of question is one of the three following:
The sourceforge channel on irc.freenode.net
Email support at sfnet_ops#geek.net
Open a ticket at https://sourceforge.net/p/forge/site-support/new/
While we do sort of monitor Stackoverflow, it's not our fastest support channel. I've asked one of our support engineers to take a look.
Here is how to connect:
select protocol SCP
Click Advanced
Environment --> SCP/Shell --> Shell (see 3 in red): change the shell that is available on the target server
It can connect to Windows 10's ssh server, with git bash

How can I keep an ssh connection open on windows and use it with perl?

I am trying to work on a old script of mine that I was writing to backup file on my VMware server.
Originally the script was going to run on Linux only, but now I trying to figure out how to make it run on Windows. Most of the modules I need for perl will run on Windows and Linux which is good. But there is one module that I can't seem to find, which is an SSH module.
My plan was to use putty or plink to send commands to the server and return them to the script. But the problem that I see is every time I call putty in the script its going to open new connection to server and close it when it has finished. What I am looking for is a way to open a connection once its open leave it open and then send and receive from that one connection. Only having it close when the script calls a close function or something.
Any idea where I could being with something like this?
Unless someone else has a much better idea because I am open to anything.
There's quite a few SSH client modules from CPAN, such as Net::SSH, Net::SSH::Perl, and Net::SSH2.
You can also try using Expect
http://metacpan.org/pod/Expect

How to spawn Linux process from Windows application?

My interactive 32-bit Windows app (now moving from Delphi [Ent] 2007 to 2009) uses command-line interactions to spawn child processes that do computationally-intensive tasks, which in turn write text files that the GUI parent app parses and analyzes - resulting in an interactive graphical display of the results.
I have access to a multiprocessor (multi-user) Linux cluster (via ssh), and would like to off-load the heavy lifting to that cluster. My question is how to spawn the processes in Linux from my Windows app. I can envision using secure FTP to put and get files, but not sure how to spawn the child processes in Linux.
Some leads for further reading would be fine - but code/pseudocode would be ideal. I can imagine that this may be more about Windows-Linux interaction than Delphi.
if you have access to ssh, one option is to issue commands through that.
For example:
ssh user#host ls -l ~
will in the ssh terminal show the files in the user's home directory. I'm not sure if this is what you really want. But it would likely work.
If you do this, you almost certainly want to setup SSH password less logins
However, A more ideal solution would likely be to setup a daemon on the linux boxes whose sole job is to run specific long running tasks in the background and let you fetch the results later.
You're going to have to install something on the Linux machine to run the process. You might find some kind of clustering or batch job submission API you can install and access from Windows. You might have to code a custom server. You might be able to run everything over ssh if you can drive an ssh process from Windows and if you have sshd installed on the Linux side. But my preference would be to write a webservice or simple CGI script on the Linux side designed to take your arguments and data and return the result over plain old http (or https as the case might be).
One way or another, this is going to encompass more than just coding on the Windows side.
I would download the full "putty" package.
As well as the excellent secure shell terminal, it includes PSCP to transfer files securely and PLINK to remote execute commands over SSH.
Hint: you will need to set up the full public/private key configuration for PLINK to work without an annoying password prompt. There is a useful guide http://unixwiz.net/techtips/putty-openssh.html>here.

Resources