Solved

ActiveX FTP Upload control with status

Posted on 2002-06-21
5
579 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Check Disk (CHKDSK) on all volumes and fix if needed. 8 178
DIR issue 7 50
VBA filters 2 50
VB6 - Compare and highlight cell not the same 3 42
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

912 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

20 Experts available now in Live!

Get 1:1 Help Now