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
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
Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias _
"FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, _
ByVal lpszDirectory As String) As Boolean
Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" ( _
ByVal hConnect As Long, ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, ByVal fFailIfExists As Long, _
ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, _
ByRef dwContext As Long) As Boolean
Function RecupFTP(serveur$, port%, login$, password$, DirOfFileToGet$, NameOfFileToGet$, TargetFullname$) As Boolean
ConnectionInternet = InternetOpen("", 1, "", "", 0)
If ConnectionInternet Then _
ConnectionFTP = InternetConnect(ConnectionInternet, serveur, port, login, password, 1, 0, 0)
If FtpSetCurrentDirectory(ConnectionFTP, DirOfFileToGet) Then _
RecupFTP = FtpGetFile(ConnectionFTP, NameOfFileToGet, TargetFullname, False, 0, &H0, 0)
End Function
Sub ExempleTest()
' paramètres à ajuster chez toi :
RecupFTP _
"hd1.freebox.fr", _
21, _
"freebox", _
"", _
"/Disque dur/test", _
"TestCopieFTP.xlsx", _
"c:\CopieFTPTestOK.xlsx"
End Sub