cURL / Mailing Lists / curl-library / Single Mail

curl-library

CURL Send File Problem

From: <mail_at_mgmst.com>
Date: Sat, 26 Aug 2006 13:26:48 -0700

Dear Sirs,

I use VB 06 to manage some Upload Rutine.

I used sample VB code from your site. But no result so far.

Files:
libcurl.dll;
vblibcurl.dll;
vblibcurl.tlb;
VBVM6Lib.tlb

Are inmay project directory and im may Windows\system and Windows\System32 directories.

Even ProgressFunction do not act.

I my access those FTP addresses via my FTP client with no problems, using the same Login and Password.
Please help?

Please see code below:

This is how I call the VBCURLLib

Private Function FuncDataSend()

Call FTPUpload.SENDDATA(vb.App.Path & "\" & "InetTest.txt", "ftp://ftp.mgmst.eu/InetTest.txt", "******", "*******")

OR

Call FTPUpload.SENDDATA(vb.App.Path & "\" & "InetTest.txt", "ftp://ftp.mgmst.eu/public_html/mgmst/", "******", "*****")
End Function

This is exact sample code from your site with my custom declaration and my xustom line of code in SENDATA function:

' $Id: FTPUpload.bas,v 1.1 2005/03/01 00:06:26 jeffreyphillips Exp $
' Demonstrate FTP Upload capability

Const GENERIC_READ = &H80000000
Const FILE_ATTRIBUTE_NORMAL = &H80
Const OPEN_EXISTING = 3
Const INVALID_HANDLE_VALUE = -1

Declare Function CreateFile Lib "kernel32" _
    Alias "CreateFileA" (ByVal lpFileName As String, _
    ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, _
    ByVal lpSecurityAttributes As Long, _
    ByVal dwCreationDisposition As Long, _
    ByVal dwFlagsAndAttributes As Long, _
    ByVal hTemplateFile As Long) As Long
Declare Function ReadFile Lib "kernel32" ( _
    ByVal hFile As Long, ByVal lpBuffer As Long, _
    ByVal nBytesToRead As Long, ByRef nBytesRead As Long, _
    ByVal lpOverlapped As Long) As Long
Declare Function CloseHandle Lib "kernel32" ( _
    ByVal hObject As Long) As Long
Declare Function GetFileSize Lib "kernel32" ( _
    ByVal hFile As Long, ByRef lpFileSizeHigh As Long) As Long

Public Sub SENDDATA(InObStrSourcePath As String, InObStrWEBPath As String, InObStrLOGIN As String, InObStrPAssword As String) 'This is my custom declaration
    'FTPUpload "d:\temp\myfile.dat", "ftp://ftp.mysite.net/myfile.dat", "ftpUserName", "ftpPassword"
    Call FTPUpload(InObStrSourcePath, InObStrWEBPath, InObStrPAssword, InObStrLOGIN) ' This is my custom line
End Sub

Private Sub FTPUpload(fileName As String, destURL As String, userID As String, password As String)
    Dim easy As Long
    Dim code As CURLcode
    Dim userPwd As String
    Dim fileSize As Long, fileSizeHigh As Long
    
    Dim fHandle As Long
    fHandle = CreateFile(fileName, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
    If (fHandle = INVALID_HANDLE_VALUE) Then
        Exit Sub
    End If

    easy = vbcurl_easy_init()

    vbcurl_easy_setopt easy, CURLOPT_READFUNCTION, AddressOf ReadFunction
    vbcurl_easy_setopt easy, CURLOPT_READDATA, fHandle
    vbcurl_easy_setopt easy, CURLOPT_URL, destURL
    userPwd = userID & ":" & password
    vbcurl_easy_setopt easy, CURLOPT_USERPWD, userPwd
    vbcurl_easy_setopt easy, CURLOPT_UPLOAD, 1
    fileSize = GetFileSize(fHandle, fileSizeHigh)
    vbcurl_easy_setopt easy, CURLOPT_INFILESIZE, fileSize
    vbcurl_easy_setopt easy, CURLOPT_NOPROGRESS, 0
    vbcurl_easy_setopt easy, CURLOPT_PROGRESSFUNCTION, AddressOf ProgressFunction
    
    code = vbcurl_easy_perform(easy)
    vbcurl_easy_cleanup easy
    
    CloseHandle (fHandle)
End Sub

' This is where the thin libcurl.vb architecture shines! In this case,
' we've passed the handle of the opened file to upload in the extra
' parameter and the address to which to write the file data in the
' bytePtr parameter. Note that these are both used directly in the
' call to the ReadFile API function, without the need for any kind
' of intermediate processing.
Private Function ReadFunction(ByVal bytePtr As Long, ByVal sz As Long, ByVal nmemb As Long, ByVal extra As Long) As Long
    Dim bytesToRead As Long, bytesRead As Long, readResult As Long
    bytesToRead = sz * nmemb
    readResult = ReadFile(extra, bytePtr, bytesToRead, bytesRead, 0)
    ReadFunction = bytesRead
End Function

' Prototype for a standard progress function
Private Function ProgressFunction(ByVal extra As Long, ByVal dlTotal As Double, ByVal dlNow As Double, ByVal ulTotal As Double, ByVal ulNow As Double) As Long
    ' just print the data
    Debug.Print "dlTotal=" & dlTotal & ", dlNow=" & dlNow & ", ulTotal=" & ulTotal & ", ulNow=" & ulNow
    ProgressFunction = 0
End Function

 
Received on 2006-08-26