cURL / Mailing Lists / curl-users / Single Mail

curl-users

Curl & VB6 & Capture the Output of a DOS application

From: Tom Gilmour <tgilmour_at_netsurf.net>
Date: Sun, 17 Jan 2010 17:09:06 -0500

This is a very Cool way of using the Curl Command line tool with VB6.
I expect it could be adapted to work with any of the Visual Studio Programming Languages.
First let me thank Marco Pipino for his program "Capture the Output of a DOS application".

I give Mark all the credit for this.

To start with you are going to have to go and get (Capture the Output of a DOS application) by Mark - Down load his code:
http://www.freevbcode.com/ShowCode.ASP?SearchString=Capture%20the%20Output%20of%20a%20DOS%20application&ID=3957

Then In a VB6 Modual:
---------------------------------

Option Explicit

Private objDOS As DOSOutputs
Public OK_Continue as Boolean

'---------------------------------------------------
Public Sub Main

    A$ = Hello_MY_SERVER("C:\curl\curl -v --no-sessionid --cacert C:\Curl\cacert.pem -u XYZ3133:E234456345 ftps://inbound.mysite.com:20026/Pickup/")
    
    If Len(A$) = 0 Then
        MsgBox "Nothing Returned from Curl ?", vbCritical
        Exit Sub
    Else
        If InStr(A$, "User logged in, proceed") = 0 Then
            MsgBox "Failed to connect to My Favorite FTPs site - call Joe Blow", vbCritical, "Senior Consultant Fred Flintstone - Fred Flintstone_at_Bigbank.com - Phone: 905-951-1627"
            frmFTP_EDI210.Show
            A$ = Replace(A$, "ACDE12345", "xxxxxxxxxxxx") 'Mask the password
            frmFTP_EDI210.RichTextBox1.Text = A$

            OK_Continue = False
            Do
                DoEvents
            Loop While Not OK_Continue
            
            Dim out As Object 'create object variable
            'assign Outlook.Application to object variable
            Set out = CreateObject("Outlook.Application")
            With out.CreateItem(olMailItem) 'using the Outlook object
                'insert recipients one at a time with the Add method
                '(these names are fictitious--replace with your own)
                .Recipients.Add "Sammy_at_nowhere.com" 'To: field
                'to place users in the CC: field, specify olCC type
                .Recipients.Add("Fred Flintstone_at_Bigbank.com ").Type = olCC
                
                .Subject = "Mucky_Muck to Fred Flintstone EDI 214 Failure" 'include a subject field
                
                .Body = "Hello Sammy & Fred: " & vbCrLf & _
                        "Unable to send EDI210 File. " & vbCrLf & _
                        "Unable to log into MY_SERVER's FTPs site." & vbCrLf & _
                        "Note: Password has been masked (xxxxxxxxxxxx) " & vbCrLf & _
                        "-------------------------------------------------" & vbCrLf & _
                        A$
            
                'insert attachments one at a time with the Add method
            ' .Attachments.Add "c:\vb6sbs\less14\smile.bmp"
                'finally, copy message to Outlook outbox with Send
               .Send
            End With
            Set out = Nothing
            
            Exit Sub
        End If
    End If
End Sub
'-----------------------------------------------------

Public Function Hello_MY_SERVER(CommandLine As String) As String

'CommandLine = "C:\curl\curl -v --no-sessionid --cacert C:\Curl\cacert.pem -u XYZ3133:E234456345 ftps://inbound.mysite.com:20026/Pickup/"

    Set objDOS = New DOSOutputs
    On Error GoTo errore
    objDOS.CommandLine = CommandLine
    objDOS.ExecuteCommand
    Hello_MY_SERVER = objDOS.Outputs
    Set objDOS = Nothing

Exit Function
'----------------------------------
errore:
    MsgBox Err.Description & " - " & Err.Source & " - " & CStr(Err.Number), vbCritical, "Error in Hello_My_Server"
    Hello_MY_SERVER = ""
End Function

'-------------------------------------------------------------
Public Function Erase_The_EDI997_File(ReceivePath As String, EDI997_File_Name As String) As Boolean

Dim Results As String
Dim CommandLine As String

    Set objDOS = New DOSOutputs
    CommandLine = "C:\curl\curl --no-sessionid -v --cacert C:\Curl\cacert.pem -u ACDE12345:Password -X " & Chr$(34) & "DELE " & EDI997_File_Name & Chr$(34) & " ftps://inbound.mysite.com:20026/PickUp/"
    On Error GoTo errore
    objDOS.CommandLine = CommandLine
    objDOS.ExecuteCommand
    Results$ = objDOS.Outputs
    Set objDOS = Nothing
    
    frmFTP_EDI210.RichTextBox1.Text = The_Results
  
Exit Function
'----------------------------------
errore:
    MsgBox (Err.Description & " - " & Err.Source & " - " & CStr(Err.Number))
End Function
'-----------------------------------

Public Function Get_EDI997_File_Name _
( _
    ReceivePath As String _
) As String
Dim A As String
Dim B As String
Dim I As Integer
Dim Fout As Integer
Dim Fin As Integer
Dim CommandLine As String

    Set objDOS = New DOSOutputs
    
    CommandLine = "C:\curl\curl -v --no-sessionid --cacert C:\Curl\cacert.pem -u ACDE12345:Password ftps://inbound.mysite.com:20026/Pickup/"
    On Error GoTo errore
    objDOS.CommandLine = CommandLine
    objDOS.ExecuteCommand
    A$ = objDOS.Outputs
    
    Fout% = FreeFile
    B$ = ReceivePath$ & "\Get_EDI997_File_Name.txt"
    Open B$ For Output As Fout%
    Print #Fout%, A$
    Close #Fout%
    
    Fin% = FreeFile
    Open ReceivePath$ & "Get_EDI997_File_Name.txt" For Input As Fin%
    Do While Not EOF(Fin%)
        Line Input #Fin%, B$
'-rw------- 1 user group 693 Dec 29 09:48 out0000988200912290001oo.cx3
        If InStr(B$, ".cx3") > 0 Then
            I% = InStr(B$, " out")
            If I% > 0 Then
                Get_EDI997_File_Name = Trim$(Mid$(B$, I% + 1))
                Close #Fin%
                Exit Function
            End If
        End If
    Loop
    Close #Fin%
    Get_EDI997_File_Name = ""
  
Exit Function

End modual
'--------------------------------------
In a Form

Private Sub cmdQuit_Click()
    OK_Continue = True
    Unload Me
End Sub

Private Sub Form_Load()
    'Center Screen
    Me.Top = (Screen.Height - Me.Height) / 2
    Me.Left = (Screen.Width - Me.Width) / 2
End Sub

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-01-17