Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ActiveX FTP Upload control with status

Posted on 2002-06-21
5
Medium Priority
?
597 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 800 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

705 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