CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Aug 2001
    Location
    Mo, US
    Posts
    2

    How to connect VB with Unix?

    Hello,
    Is there a way to connect to Unix using VB. If there is a way, can you use Unix commands and execute them. Can someone send me a small project or code on how to go about doing this.
    Thanks,


  2. #2
    Join Date
    Aug 2001
    Posts
    26

    Re: How to connect VB with Unix?

    you said that you would like to connect to unix using VB code that can be done you should use the winstock control which helps you to connect to the unix port and talk to unix system.

    first connect to unix server by typing wistock1.connect
    then specify the protocol either tcp/ip e.t.c
    then use winstock1.senddata to send the unix command and if taht command returns some value that can be captured by winstock1.getdata commnad

    i hopw this will help you as i have done the similar case before.



  3. #3
    Join Date
    Aug 2001
    Location
    Mo, US
    Posts
    2

    Re: How to connect VB with Unix?

    Thankyou bhanuprakash!
    Is there a small project or code that you might have some where that I can see.


  4. #4

    Re: How to connect VB with Unix?

    include a winsock control (winsock1) in your form


    private sub Button1_click()
    winsock1.connect "myUnixMachine",23
    end sub

    private sub winsock1_connect()
    debug.print "connect to unix system"
    '/* now I try a logon
    winsock.senddata "myuser" & vbcrlf
    winsock.senddata "mypwd" & vbcrlf
    end sub

    private sub winsock1_dataarrival(byval bytes as long)
    dim Unixdata as string
    winsock1.getdata unixstring
    debug.print unixstring
    end sub

    private sun winsock1_close()
    debug.print "Connection close."
    end sub

    private sun winsock1_error(...)
    debuug.print "error."
    end sub

    private button2_click()
    '/* use to send command to remote machine
    winsock1.senddata text1.text & vbcrlf
    end sub

    private button3_click()
    '/* use to close connection
    if winsock1.state <> sckclosed then winsock1.close
    'or -> winsock1.senddata "quit" & vbcrlf
    end sub




    hi,brt

    <center>
    <HR width=80%>
    <img src='http://web.tiscali.it/bertaplanet/im...ertaplanet.gif'>
    </center>

  5. #5
    Join Date
    Oct 2002
    Posts
    36

    urgent

    can u all send me the code about how to connect vb to unix server and send the command to unix server.(example: send the command to unix sever which is run pearl script in unix server ) i am urgent to need it and it can help me a lot ....thanx a lot to u all...

  6. #6
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792
    The code is above !

  7. #7
    Join Date
    Oct 2002
    Posts
    36
    ok...thanx a lot ....rite now i am using visual basic to design interface and i have to create file in unix and store my data ifrom VB interface into unix. is that possible to do it ? and how can get more inoformation about winsock method.

  8. #8
    ...Yes it's possible...
    yuo can user unix command using socket...
    after yuo have the logon u can use

    echo "my data string" >> myfile

    ..so you can store your data in "myfile" on unix ....

    example on socket control? yuo can look on MSDN... there is a good sample of client-server =)

    hi
    M.rkino

  9. #9
    Join Date
    Oct 2002
    Posts
    36
    thanx....ehmmm is there an example or code that you might have some where that I can see.

  10. #10
    Join Date
    Oct 2002
    Posts
    36

    Unhappy urgent...connect unix server

    i am not clear with how to typr the unix command in visual basic....so can anyone help me ...and i cannot connect to unix server so can brief me more clearly??thanx a lot..

  11. #11
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792
    Show what you already have, and we'll try to figure out where you're going wrong. Its a little difficult to help, when we can't see where you're up to, and what you're doing wrong.

  12. #12
    Join Date
    Oct 2002
    Posts
    36
    because i donno whether i already connect to unix server already or not...how can i know it???this is my code actually i want to view my file which name testing...but i can't get the content of my file.i just the first time use winsock so.....

    Option Explicit



    Private Sub cmdclose_Click()
    Winsock1.Close

    End Sub

    Private Sub cmdConnect_click()

    Winsock1.Connect "unixserver",23

    shpGo.Visible = True

    End Sub



    Private Sub cmdsend_Click()
    Winsock1.SendData txtfile.Text & vbCrLf
    End Sub

    Private Sub Winsock1_Close()
    Debug.Print "Connection close."

    End Sub

    Private Sub winsock1_connect()
    Debug.Print "connect to unix server system"
    Winsock1.SendData "myuser" & vbCrLf
    Winsock1.SendData " mypass" & vbCrLf
    Winsock1.SendData "cat testing" & vbCrLf 'i want to view the content of file ( unix command)
    shpWait.Visible = True
    shpGo.Visible = False

    End Sub

    'i got error in this part,what shuld i put in my case
    Private Sub winsock1_dataarrival(ByVal bytes As Long)
    Dim Unixdata As String
    Winsock1.GetData unixstring
    Debug.Print unixstring
    End Sub



    Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    Debug.Print "error"
    End Sub

  13. #13
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792
    Try

    Private Sub winsock1_connect()
    dim strConnected as string

    on error goto errtrap
    strConnected = "Connected"
    Debug.Print "connect to unix server system"
    Winsock1.SendData "myuser" & vbCrLf
    Winsock1.SendData " mypass" & vbCrLf
    txt1.text = strconnected
    Winsock1.SendData "cat testing" & vbCrLf 'i want to view the content of file ( unix command)
    shpWait.Visible = True
    shpGo.Visible = False

    exit sub
    ErrTrap:
    msgbox "Error Number " & err.number & vbcrlf & _
    "Error Description " & err.description
    err.clear
    End Sub


    In your 'dataArrival' sub, you need to get the size of the bytes, then convert the buffer to a string - I used to have some code that did it, but I appear to have lost it over the years. Somebody else here may either have a link to the articles on MSDN, or may have some code taht will help you out for that bit.

  14. #14
    Join Date
    Oct 2002
    Posts
    36
    if i run the program then the msg box in vb is prompt out RFB 003.003..what is meaning for??? if i use vnc(virtual network control to connect my unix server ...then how can i send the command in visual basic to the vnc window??? thanx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured