1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
Module ClassFTP_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 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
Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Public FTP_URL = "XXX"
Public FTP_login = "XXX"
Public FTP_passwd = "XXX"
Public Sub Test_FTP()
Dim lngINet As Long
Dim lngINetConn As Long
Dim blnRC As Boolean
'ouverture session
lngINet = InternetOpen("siteweb", 1, vbNullString, vbNullString, 0)
'nom_session, acces direct (no proxy), nom proxy, bypass proxy, lFlags
' On ouvre une session
If (lngINet <> 0) Then
' On ouvre une connection
lngINetConn = InternetConnect(lngINet, FTP_URL, 21, FTP_login, FTP_passwd, 1, 0, 0)
'session, hote a contacter, port 21, login, password, type FTP, lFlags, lContext
If lngINetConn <> 0 Then
' download
blnRC = FtpGetFile(lngINetConn, "test.txt", "c:\test.txt", 0, 0, 1, 0)
'connexion, fichier source, fichier destination, overwrite, lFlags, type ASCII, lContext
If (blnRC = False) Then
MsgBox("Erreur : " & blnRC)
Else
MsgBox("Ok : " & blnRC)
End If
Else
MsgBox("Connect Erreur")
End If
' On quitte proprement
If lngINetConn <> 0 Then InternetCloseHandle(lngINetConn)
If lngINet <> 0 Then InternetCloseHandle(lngINet)
Else
MsgBox("Pas de Connection.")
End If
End Sub
End Module |
Partager