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

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

Related

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.

MobaXterm drag-and-drop panel missing

I need to run a program from my windows xP machine thats installed on a remote UNIX machine using MobaXterm but I have very little experience with this sort of thing.
I can login into the machine using ssh and start the program without a problem. That program needs files that I have on my windows computer to process though and I want to copy them over to that remote machine. Unfortunately the drag-and-drop file transfer panel that is mentioned regularly on mobaxterm help sites isn't present and I can't figure out how to make it appear.
Could someone suggest how to get that drag-and-drop panel to appear please? I'm using MobaXterm version 3.0.
Alternatively any explanation on how to transfer these files another way would also be very much appreciated.
Thank you very much for any help you can give.
If it still doesn't work when you try all of above methods, try this:
when you creat a Session, change the Advanced SSH setting-->SSH-browser type to SCP, which default is SFTP.
. thanks to willfurnass
Some Linux distributions or some other Unix systems have disabled SSH password authentication by default.
In order for MobaXterm to be able to launch the SFTP browser, you will have to re-enable this feature:
Edit the "/etc/ssh/sshd_config" file on your server, and comment the following line:
PasswordAuthentication no
Restart your SSH server using the following command: /etc/init.d/sshd restart
Connect using MobaXterm SSH client and you will notice that the SFTP tab will be correctly launched.
If you can not modify your remote server configuration, you can also perform your file transfers inside MobaXterm terminal using SCP. A sample SCP command would be:
scp -r /drives/c/Some/Place/On/Your/Local/Windows/Drive/ yourlogin#yourserver:/Some/Place/On/Your/Remote/Unix/Server/
Ensure you have "Display SFTP Browser" enabled in your session settings under "Advanced SSH settings".
Occasionally it doesn't reappear, which is solved by a restart MobaXterm.
Another cause for the lack of sftp panel is if you accidentally enter and store a bad sftp password. MobaXterm then appears to attempt an automatic log in, but silently fails to open the sftp connection.
To fix this, go to Settings>MobaXterm passwords management and delete the offending password. Here's a screenshot of the settings page, showing the password management link.
To be clear, I had already run through the settings mentioned by #Nicolas and #Didier (thanks, guys!). I was able to get the sftp tab when ssh'ing in to other hosts (which didn't have bad passwords stored). And I had in the past seen the sftp pane. This fix solved my problem.
If you've never seen the sftp pane, then try the other suggestions first.
Have you tried:
Turning the program off and on again?
Note: I read this hint in a comment, which saved me from a tidious process of unnecessary fixing mobaXterm, also I am hence not the only one with that behavior. Even though this might be the first thing you already tried, some might not have been trying and haven't been lucky enough to read through the comments - this is for them.
For the most recent versions, ensure you have selected 'SFTP protocol' in the'SSH-browser' selector:

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

Invoking windows batch file from Linux

I have an application running only on Windows and a batch file that launches it.
I want to invoke this batch file from Linux, meaning something like Linux batch will launch the windows batch with parameters and this in its turn run my application.
Can I do that? How?
You could install an ssh server in the windows box (Cygwin has one), then from linux do something like:
ssh user#windows-box c:/path/to/batch.cmd
and that should launch your application in the windows box.
The most direct way is probably to install an ssh server on the windows box. Cygwin includes an ssh server.
Depending on how precise your timing needs are, you might be able to have an "at" job on the windows box that runs periodically (every 5 minutes?) and runs if it sees that a particular file exists, deleting the file. Then you could use Samba/smbclient to create the file. You would need to turn on filesharing on the windows box for this to work.
If the windows box has a web server, you could write a CGI, and trigger it using wget or cURL.
Our build process currently goes the other way: a windows sever kicks off things on the Linux server using plink (part of PuTTY). You might be able to set something similar up.
This may cause a security issue. Our information security person did not allow me to invoke any programs directly.
The safer way is to set up server on Windows computer. This can be a web-server for example. And then invoke your process inside PHP/Perl/Python script.
Also look at winexe that allows you to execute windows commands/batch scripts without running ssh server.

How to send commands to 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.

Resources