Hello Luis,
I find an example on
http://vbnet.mvps.org/index.html?code/internet/ftplist.htm
where a extracted the code you need which you can find below.
grtz
*********************************************************
Global Const FTP_TRANSFER_TYPE_ASCII = &H1
Global Const FTP_TRANSFER_TYPE_BINARY = &H2
Global Const INTERNET_DEFAULT_FTP_PORT = 21
Global Const INTERNET_SERVICE_FTP = 1
Global Const INTERNET_FLAG_PASSIVE = &H8000000
Global Const GENERIC_WRITE = &H40000000
Global Const BUFFER_SIZE = 100
Global Const PassiveConnection As Boolean = True
Global Const MAX_PATH As Long = 260
Declare Function SQLDataSources Lib "ODBC32.DLL" ( _
ByVal henv As Long, ByVal fDirection As Integer, _
ByVal szDSN As String, ByVal cbDSNMax As Integer, _
pcbDSN As Integer, ByVal szDescription As String, _
ByVal cbDescriptionMax As Integer, pcbDescription As Integer _
) As Integer
' Declare wininet.dll API Functions
Public Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias
"FtpSetCurrentDirectoryA" _
(ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Public Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias
"FtpGetCurrentDirectoryA" _
(ByVal hFtpSession As Long, ByVal lpszCurrentDirectory As String,
lpdwCurrentDirectory As Long) As Boolean
Public Declare Function InternetWriteFile Lib "wininet.dll" _
(ByVal hFile As Long, ByRef sBuffer As Byte, ByVal lNumBytesToWite As Long, _
dwNumberOfBytesWritten As Long) As Integer
Public Declare Function FtpOpenFile Lib "wininet.dll" Alias "FtpOpenFileA" _
(ByVal hFtpSession As Long, ByVal sBuff As String, ByVal Access As Long,
ByVal Flags As Long, ByVal Context As Long) As Long
Public Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" _
(ByVal hFtpSession As Long, ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Public Declare Function FtpDeleteFile Lib "wininet.dll" _
Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, _
ByVal lpszFileName As String) As Boolean
Public Declare Function InternetCloseHandle Lib "wininet.dll" _
(ByVal hInet As Long) As Long
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 FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" _
(ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal
dwFlagsAndAttributes As Long, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Declare Function InternetGetLastResponseInfo Lib "wininet.dll" _
Alias "InternetGetLastResponseInfoA" _
(ByRef lpdwError As Long, _
ByVal lpszErrorBuffer As String, _
ByRef lpdwErrorBufferLength As Long) As Boolean
Declare Function FtpFindFirstFile Lib "wininet" _
Alias "FtpFindFirstFileA" _
(ByVal hConnect As Long, _
ByVal lpszSearchFile As String, _
lpFindFileData As Any, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As Long
Public Declare Function InternetFindNextFile Lib "wininet" _
Alias "InternetFindNextFileA" _
(ByVal hFind As Long, _
lpFindFileData As WIN32_FIND_DATA) As Long
Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Sub ftpForLuis()
Dim hConnection, hCurDir, hDir, hFile, hOpen As Variant
Dim WFD As WIN32_FIND_DATA
Const hostname = "
www.domain.org"
Const path = "/yourpath/yoursubpath/"
Const username = "yourusername"
Const password = "yourpassword"
hOpen = InternetOpen("FTP", 1, "", vbNullString, 0)
hConnection = InternetConnect(hOpen, hostname, INTERNET_DEFAULT_FTP_PORT,
username, password, INTERNET_SERVICE_FTP, IIf(PassiveConnection,
INTERNET_FLAG_PASSIVE, 0), 0)
hDir = FtpSetCurrentDirectory(hConnection,
"/tbr-umcu/www/cobra2000/downloads/")
hFile = FtpFindFirstFile(hConnection, _
path, WFD, _
INTERNET_FLAG_RELOAD Or _
INTERNET_FLAG_NO_CACHE_WRITE, 0&)
If hFile Then
Do
tmp = Left(WFD.cFileName, InStr(WFD.cFileName, Chr(0)))
If Len(tmp) Then
If WFD.dwFileAttributes And vbDirectory Then
MsgBox (tmp) ' List1.AddItem tmp & sSlash
Else
MsgBox (tmp) ' List1.AddItem tmp
End If
End If
'continue while valid
Loop While InternetFindNextFile(hFile, WFD)
End If
InternetCloseHandle (hFile)
InternetCloseHandle (hOpen)
InternetCloseHandle (hConnection)
End Sub