Option Explicit
Option Base 1
Const FTP_Adresse = "........"
Const FTP_Login = "....."
Const FTP_Mot_de_Passe = "....."
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
cAlternate As String * 14
End Type
'aide sur les fonction
' Private Declare PtrSafe Function --> https://docs.microsoft.com/fr-fr/office/vba/language/reference/user-interface-help/declare-statement?f1url=%3FappId%3DDev11IDEF1%26l%3Dfr-FR%26k%3Dk(vblr6.chm1008781);k(TargetFrameworkMoniker-Office.Version%3Dv16)%26rd%3Dtrue
' wininet.dll ----------------------> https://docs.microsoft.com/en-us/windows/win32/wininet/ftp-sessions
' Open the Internet object
Private Declare PtrSafe 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
'
' Connect to the network
Private Declare PtrSafe 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
'
' Close the Internet object
Private Declare PtrSafe Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
'
' Get a file using FTP
Private Declare PtrSafe 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
'
' Send a file using FTP
Private Declare PtrSafe 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
'
' Searches the specified directory of the given FTP session. File and directory entries are returned to the application in the WIN32_FIND_DATA structure.
Private Declare PtrSafe Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As WIN32_FIND_DATA, ByVal lpFindFileData As String, ByVal dwFlags As Long, ByVal dwContext As Long)
'
Private Sub test()
Dim HwndConnect As Long
Dim HwndOpen As Long, MyFile
Dim toto As WIN32_FIND_DATA
' Initialisation de la connexion FTP
HwndOpen = InternetOpen("connexionFTP", 0, vbNullString, vbNullString, 0)
' Connexion au serveur FTP
HwndConnect = InternetConnect(HwndOpen, FTP_Adresse, 21, FTP_Login, FTP_Mot_de_Passe, 1, 0, 0)
MyFile = FtpFindFirstFile(HwndOpen, toto, vbNullString, 0, 0)
' Fermeture des connexions
InternetCloseHandle HwndConnect
InternetCloseHandle HwndOpen
End Sub