VB & SSH
-
Thursday, March 27, 2008 10:08 PM
I will begin by letting you know I am new to this forum and new to Visual Studio. I am a student at Arizona State University and through DreamSpark have been able to download and install Visual Studio 8 at no cost (awesome!). I am building an application that I would like to use to automatically connect to a remote host through SSH. The host is an ASU host and all I would like is to download a specific file from the host to be manipulated further by my program. I have access to the host, as assigned to me through ASU. Normally, I would just use the 'SSH Secure Shell Client' program (which has been provided to me) to download any files manually. However, I would prefer an automated program that eliminates any extra work that I do to the file after downloading (this work is always the same). So there you have the background story and general idea of why and what I am attempting to do.
In order to accomplish my task it appears that I have to buy an SSH ActiveX Component. Before I do this I want to know that I can accomplish my task with that component or else I would have just wasted my money. There is only one such COM that I have found which has a trial. It is here: http://www.ssh-activex.com/. That is what I am using.
Now, here is my code.
Private Sub butImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butImport.Click
Dim SSH As New MySSH
Dim EXE As String = "cd " & My.Settings.ServerLocation & " |ls -al"
SSH.ExecCommand(My.Settings.ServerHostName, My.Settings.ServerPortNumber, _
My.Settings.ServerUserName, My.Settings.ServerPassword, EXE)
MsgBox(SSH.Result)
End Sub
As you can see, when the button is clicked, I use the COM to connect to the server and display the results in a MsgBox. I am doing this to verify that it is working. I am able to verify that it is connecting because it does return results. The problem, however, is that it is not changing the directory as I am specifying it to do. The result returned is always the root directory.
Can anyone help me with this problem?
All Replies
-
Thursday, March 27, 2008 11:13 PM
That command is trying to pipe cd into ls, which doesn't make sense. To list the folder contents just do "ls -la path".
For Windows to *nix I use winSCP for transfering files...
http://winscp.net/eng/download.php
and putty (with xming for an xserver) to make ssh connections...
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html -
Thursday, March 27, 2008 11:31 PM
Thanks for the reply. That solution, though, is returning no results. I know for a fact there are files in the folder. Here is the modified code (very straight forward):
Private Sub butImport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butImport.Click
Dim SSH As New MySSH
Dim EXE As String = "ls -la " & My.Settings.ServerLocation
SSH.ExecCommand(My.Settings.ServerHostName, My.Settings.ServerPortNumber, _
My.Settings.ServerUserName, My.Settings.ServerPassword, EXE)
MsgBox(SSH.Result)
End Sub
Any ideas?
Given I am new to SSH, I cannot say that I know how to utilize those resources you listed. Would you mind elaborating as to what they are? Would they be better alternatives for what I am doing? All I need to do is connect to that folder (My.Settings.ServerLocation) and download a single file.
Thanks.
-
Friday, March 28, 2008 12:07 AM
Well, I figured out one thing. By removing the -la parameters it returns exactly what I was looking for. Next step, figuring out how to download. I believe I am learning though that I cannot actually get the file onto the local machine through SSH. I will have to use SCP?
I will see what I can figure out, hopefully this will be a good reference for people with a similar goal as mine in the future.
-
Friday, March 28, 2008 12:38 AMwinSCP is the way to go. It's free as in beer.

