Solved

ActiveX FTP Upload control with status

Posted on 2002-06-21
5
576 Views
Last Modified: 2012-05-04
I am trying to create an ActiveX control to be used in IE that will enable uploading of multiple files via FTP.  I need to provide an escape mechanism ('cancel' button) to be accessable during the upload also.  This has caused me to start working with the wininet.dll more specifically the functions FtpOpenFile and InternetWriteFile.  I have downloaded the simpleFTP program (vbsmpftp proj) from Microsoft, and the code supplied there works for uploading.  However, when I try to put it into an ActiveX control to be used within IE, I end up only getting garbage data (looks like possible memory values) in the resulting file that was uploaded.  

If more points are warrented, I'll up them later.

Thanks,
 Jon


Here is the code:

If hOpen = 0 Then
      ErrorOut Err.LastDllError, "InternetOpen"
    End If
   
    If hConnection <> 0 Then
        InternetCloseHandle hConnection
    End If
   
    hConnection = InternetConnect(hOpen, "vijay", INTERNET_INVALID_PORT_NUMBER, _
                                  "user", "user_passwd", INTERNET_SERVICE_FTP, 0, 0)
   
    If hConnection = 0 Then
        ErrorOut Err.LastDllError, "InternetConnect"
        GoTo CLOSEOUT
    End If
           
   Dim i As Long
   Dim ct As Long
   Dim path As String
   Dim filename As String
   
   ct = UBound(filesToUpload)

   Dim Data(99) As Byte ' array of 100 elements 0 to 99
   Dim Written As Long
   Dim Size As Long
   Dim Sum As Long
   Dim j As Long
   
   Sum = 0
   j = 0
   hfile = FtpOpenFile(hConnection, "cds.txt", &H40000000, FTP_TRANSFER_TYPE_BINARY, 0)
   If hfile = 0 Then
       ErrorOut Err.LastDllError, "FtpOpenFile"
       GoTo CLOSEOUT
   End If
   Open "C:\desktop\cds.txt" For Binary Access Read As #1
   Size = LOF(1)
   For j = 1 To Size \ 100
       Get #1, , Data
       If (InternetWriteFile(hfile, Data(0), 100, Written) = 0) Then
           ErrorOut Err.LastDllError, "InternetWriteFile"
           GoTo CLOSEOUT
       End If
       'DoEvents
       Sum = Sum + 100
       'Label7.Caption = str(Sum)
   Next j
   Get #1, , Data
    If (InternetWriteFile(hfile, Data(0), Size Mod 100, Written) = 0) Then
           ErrorOut Err.LastDllError, "InternetWriteFile"
           GoTo CLOSEOUT
   End If
   Sum = Sum + (Size Mod 100)
   'Label7.Caption = str(Sum)
   
CLOSEOUT:
   
   Close #1
   InternetCloseHandle hfile
   InternetCloseHandle hConnection
End Sub
0
Comment
Question by:punkrider
5 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 200 total points
ID: 7099498
What is your declaration for InternetWriteFile?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7099504
0
 

Author Comment

by:punkrider
ID: 7099596
Paul,

I looked at the declarations between the two and don't you know it, my declaration that I got off the net somewhere had the wrong type.

You hit the nail on the head.  I guess the moral of this story is 'do not trust anything on the net'.  Thanks.

Here was the wrong declaration:

Public Declare Function InternetWriteFile Lib "Wininet.dll" _
           (ByVal hfile As Long, _
            ByVal sBuffer As String, _
            ByVal lNumberOfBytesToWrite As Long, _
            lNumberOfBytesWritten As Long) As Integer

and the correct version:

Public Declare Function InternetWriteFile Lib "Wininet.dll" _
           (ByVal hfile As Long, _
            ByRef sBuffer As Byte, _
            ByVal lNumberOfBytesToWrite As Long, _
            lNumberOfBytesWritten As Long) As Integer
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 7099614
That declaration (the wrong one) may work if you are using a string instead of a byte array to store the file contents you are uploading.  Glad you got it working.  

Do you have a link to the MS sample project?  I went hunting, but I couldn't find it.
0
 

Expert Comment

by:gr53
ID: 7540680
You can download the MS sample project here:
http://download.microsoft.com/download/ie4095/vbsmpftp/1/w9xnt4/en-us/VBSMPFTP.exe

There was a support article on this support.microsoft.cok #Q195653 but it seems to be gone now.

I had the same problem, glad I found this. :)

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now