-
November 24th, 2003, 10:08 AM
#1
Telnet onto server and execute a batch file in VB
Hi,
I need to telnet onto a server and execute a batch file. Whilst no problem doing this manually, I need to do this through code. I understand I need to use winsock, but how???
Many thanks.
-
November 24th, 2003, 01:15 PM
#2
Re: Telnet onto server and execute a batch file in VB
Originally posted by jvbd02
Hi,
I need to telnet onto a server and execute a batch file. Whilst no problem doing this manually, I need to do this through code. I understand I need to use winsock, but how???
Many thanks.
start with a telnet control?
http://www.dart.com/powertcp/telnet_included.asp
-
November 24th, 2003, 01:50 PM
#3
Looks a nice control - unfortunately purchasing it is out of the question, and it'll need to be in use for longer than the 30 days trial period on offer.
I'm using winsock (through api calls and not a control). I have managed to connect and disconnect to the server, but how do I now execute the batch file.
Thanks.
-
April 29th, 2004, 03:57 PM
#4
I'm being a bit thick
After placing this on the backburner for some months I find myself addressing this problem again...
Right, I've been using winsock api's and not a winsock control cos my work PC doesn't have licences for it (sore point, let's not go there). I'm not at my work PC right now so cant post the code, but I don't think that'll be problematic - the code is naff, it doesn't work, I want to scrap it.
All I want to do, through VB (Access VBA), is connect to a UNIX box on the LAN, supply a username, then password, then, navigate to the correct directory on that box, and run a .bat file. It shouldn't be hard, but like the subject of this thread says, I am being a little thick.
Please, please help!
Thanks.
-
April 29th, 2004, 07:47 PM
#5
Use the Microsoft Winsock Control to create a TCP connection to the server and read the RFC for Telnet communications. that should enable you to send data to the telnet server.
indeed the telnet sever is only listeing for ascii characters etc.. so you just have to use the winsock.send("login ...") method.
greetings UNI
-
April 30th, 2004, 03:46 AM
#6
I wonder if it would be possible to use the windows telnet client, GetWindowText, and SendMessage APIs?
-
April 30th, 2004, 04:32 AM
#7
Monkey - will give it a go, thanks.
Ulluvatan - can't use the winsock control, only api - I've adapted code from allapi.net but it doesn't work - I am clueless as to how to code it. Here is the code, don't laugh too hard! Also this code is executed in VB5 where it doesn't crash - hooking an Access form causes mayhem on my PC!
Code:
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim sSave As String
Me.AutoRedraw = True
Set Obj = Me.Text1
'Start subclassing
HookForm Me
'create a new winsock session
StartWinsock sSave
'show the winsock version on this form
If InStr(1, sSave, Chr$(0)) > 0 Then sSave = Left$(sSave, InStr(1, sSave, Chr$(0)) - 1)
Me.Print sSave
'connect to Microsoft.com
lSocket = ConnectSock("dev01", 23, 0, Me.hwnd, False)
SendData lSocket, "user" & Chr(0)
SendData lSocket, "pass" & Chr(0)
SendData lSocket, "cd /myfolder" & Chr(0)
SendData lSocket, "my.bat" & Chr(0)
End Sub
-
April 30th, 2004, 04:46 AM
#8
it would be easier to:
1) write a cronjob for the utility
or
2) write a simple program to sit on the unix server and listen for a connection, and whenever it gets one, and maybe some authentication, run the bat file..
if you wrote a program that listene don the unix server, and scanned the first line of every communication, for the word "hello" before it ran tha bat.. then you could run the bat with a web browser:
http://UNIX_SERVER_NAME:PORT/hello
here is an example program of such, in java:
Code:
import java.io.*;
public class RunProg{
public static void main(String[] argv)throws Exception{
for(;;)
if(new BufferedReader(new InputStreamReader(new ServerSocket(80).accept().getInputStream)).readLine().indexOf("hello") > -1 )
Runtime.getRuntime().exec("/usr/me/myprog");
}
}
}
i could run it as shown above, with the web browser.
Or with vb:
Inet1.OpenURL("http://unixsrv/hello")
-
April 30th, 2004, 04:47 AM
#9
heck, if the unix box runs a webserver you could probably do it with cgi..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|