Option Explicit
Const scUserAgent = "vb wininet"
Const INTERNET_SERVICE_FTP = 1
Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_INVALID_PORT_NUMBER = 0
Const INTERNET_FLAG_PASSIVE = &H8000000
Const FTP_TRANSFER_TYPE_ASCII = 1
Private 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
Private 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
Private Declare Function InternetCloseHandle _
Lib "wininet.dll" (ByVal hInet As Long) As Integer
Private Declare Function ftpCommand _
Lib "wininet.dll" Alias "FtpCommandA" ( _
ByVal hConnect As Long, _
ByVal fExpectResponse As Boolean, _
ByVal dwFlags As Long, _
ByVal lpszCommand As String, _
dwContext As Long, _
phFtpCommand As Long) As Boolean
Private Declare Function InternetReadFile _
Lib "wininet.dll" ( _
ByVal hConnect As Long, _
ByVal lpBuffer As String, _
ByVal dwNumberOfBytesToRead As Long, _
lpdwNumberOfBytesRead As Long) As Boolean
'=======================================================
' End Declarations - Begin Procedures
'=======================================================
Private Function TrimNull$(ByVal s$)
Dim pos%
pos = InStr(s, Chr$(0))
If pos Then s = Left$(s, pos - 1)
TrimNull = Trim$(s)
End Function
Private Sub Command1_Click()
Const NUMBYTES& = 1020
Dim hOpen&, hConn&, hOutConn&, buffer$, bytesRead&
hOpen = InternetOpen( _
scUserAgent, _
INTERNET_OPEN_TYPE_DIRECT, _
vbNullString, _
vbNullString, 0)
DoEvents
If hOpen = 0 Then Exit Sub
'Note: This is coded for the anonymous Microsoft site
' See the Declare above for replacing the three
' parameters with your site, username and password.
hConn = InternetConnect( _
hOpen, _
"ftp.microsoft.com", _
INTERNET_INVALID_PORT_NUMBER, _
"", _
"", _
INTERNET_SERVICE_FTP, _
INTERNET_FLAG_PASSIVE, 0)
DoEvents
If hConn = 0 Then GoTo out2
' Command to change a Directory
ftpCommand hConn, _
False, _
FTP_TRANSFER_TYPE_ASCII, _
"CWD developr", _
0, _
hOutConn
' Command to LIST the Directory
ftpCommand hConn, _
True, _
FTP_TRANSFER_TYPE_ASCII, _
"LIST", _
0, _
hOutConn
DoEvents
If hOutConn = 0 Then GoTo out1
Text1 = ""
buffer = Space$(NUMBYTES + 4)
Do
InternetReadFile _
hOutConn, _
buffer, _
NUMBYTES, _
bytesRead
If bytesRead = 0 Then Exit Do
Text1 = Text1 & TrimNull(buffer)
Loop
InternetCloseHandle hOutConn
out1: InternetCloseHandle hConn
out2: InternetCloseHandle hOpen
End Sub
Private Sub Form_Load()
Move 1000, 1000, 5400, 3600
Text1.Move 120, 120, 5000, 2500
Command1.Move 2000, 2760, 1200, 375
End Sub
|