VB.NET / wininet.dll / InternetReadFile

Hallo Community,

untenstehendes Programm will einfach nicht laufen und nach stundenlangem(!) googlen gebe ich auf und wende mich an Euch …
die Zeile

ret = InternetReadFile(hFile, fBuf, BufSize, BytesRead)

ist das Problem … ret ist immer TRUE, BytesRead immer 0 …
Ich habe auch den Parameter hFile durch hConnection und auch durch hOpen ersetzt, es passiert immer das gleiche :frowning:

Ich lasse Username und Passwort absichtlich drin, damit jeder, der sich damit beschäftigen mag, sich überzeugen kann, daß Username, Passwort, Dateiname usw. korrekt sind.

Umgebung ist MS Visual Studio 2010 Express - Visual Basic

Public Class MainForm
 Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
 Public Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
 Public Declare Function FtpOpenFile Lib "wininet.dll" Alias "FtpOpenFileA" (ByVal hFtpSession As Long, ByVal sFileName As String, ByVal lAccess As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
 Public Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, ByRef lNumberOfBytesRead As Long) As Long


 Public Sub main()
 Const BufSize As Long = 2048
 Dim hOpen As Long, hConnection As Long, hFile As Long, BytesRead As Long
 Dim ByteBuf() As Byte
 Dim fBuf As String
 Dim ret As Boolean

 hOpen = InternetOpen("vb wininet", 1, vbNullString, vbNullString, 0)
 If hOpen = 0 Then Err.Raise(vbObjectError + 1000, , "An error occurred calling InternetOpen function")
 hConnection = InternetConnect(hOpen, "ftp.drutschi.net/", 21, "f00425c0", "FKfbFSzdCfmkHmak", 1, &H80000000, 0)
 If hConnection = 0 Then Err.Raise(vbObjectError + 1000, , "An error occurred calling InternetConnect function")
 hFile = FtpOpenFile(hOpen, "test.zip", &H80000000, 2, 0)
 If hFile = 0 Then Err.Raise(vbObjectError + 1000, , "An error occurred calling FtpOpenFile function")
 Do
 ret = InternetReadFile(hFile, fBuf, BufSize, BytesRead)
 Debug.Print(fBuf)
 Loop Until ret = True And BytesRead = 0
 End Sub

 Private Sub MainForm\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 main()
 End Sub
End Class
  • hat sich erledigt, ich habe es nun vollkommen anders gemacht :smile: