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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
Public Class FTPManagerAPI
Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Integer) As Integer
Public Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Integer, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUserName As String, ByVal sPassword As String, ByVal lService As Integer, ByVal lFlags As Integer, ByVal lContext As Integer) As Integer
Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Integer, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Integer) As Integer
Public Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Integer, ByVal lpszDirectory As String) As Boolean
Public Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias "FtpGetCurrentDirectoryA" (ByVal hFtpSession As Integer, ByVal lpszCurrentDirectory As String, ByVal lpdwCurrentDirectory As Integer) As Integer
Public Declare Function FtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" (ByVal hFtpSession As Integer, ByVal lpszDirectory As String) As Boolean
Public Declare Function FtpRemoveDirectory Lib "wininet.dll" Alias "FtpRemoveDirectoryA" (ByVal hFtpSession As Integer, ByVal lpszDirectory As String) As Boolean
Public Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Integer, ByVal lpszFileName As String) As Boolean
Public Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" (ByVal hFtpSession As Integer, ByVal lpszExisting As String, ByVal lpszNew As String) As Boolean
Public Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal hConnect As Integer, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Integer, ByVal dwFlagsAndAttributes As Integer, ByVal dwFlags As Integer, ByRef dwContext As Integer) As Boolean
Public Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hConnect As Integer, ByVal lpszLocalFile As String, ByVal lpszNewRemoteFile As String, ByVal dwFlags As Integer, ByVal dwContext As Integer) As Boolean
Public Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" (ByVal lpdwError As Integer, ByVal lpszBuffer As String, ByVal lpdwBufferLength As Integer) As Boolean
Public Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Integer, ByVal lpszSearchFile As String, ByVal lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Integer, ByVal dwContent As Integer) As Integer
Public Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (ByVal hFind As Integer, ByVal lpvFindData As WIN32_FIND_DATA) As Integer
Public Declare Function LocalFileTimeToFileTime Lib "kernel32" (ByVal lpLocalFileTime As FILETIME, ByVal lpFileTime As FILETIME) As Integer
Public Enum eTRANSFERT_TYPE
FTP_TRANSFER_TYPE_ASCII = &H1
FTP_TRANSFER_TYPE_BINARY = &H2
FTP_TRANSFER_TYPE_UNKNOWN = &H0
End Enum
Public Const INTERNET_DEFAULT_FTP_PORT As Short = 21 ' default for FTP servers
Public Const INTERNET_SERVICE_FTP As Integer = 1
Public Const INTERNET_FLAG_PASSIVE As Integer = &H8000000 ' used for FTP connections
Public Const INTERNET_OPEN_TYPE_PRECONFIG As Integer = 0 ' use registry configuration
Public Const INTERNET_OPEN_TYPE_DIRECT As Integer = 1 ' direct to net
Public Const INTERNET_OPEN_TYPE_PROXY As Integer = 3 ' via named proxy
Public Const INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY As Integer = 4 ' prevent using java/script/INS
Public Const MAX_PATH As Integer = 260
Public Const PassiveConnection As Boolean = True
Public Structure FILETIME
Public dwLowDateTime As Integer
Public dwHighDateTime As Integer
End Structure
Public Structure SYSTEMTIME
Public wYear As Integer
Public wMonth As Integer
Public wDayOfWeek As Integer
Public wDay As Integer
Public wHour As Integer
Public wMinute As Integer
Public wSecond As Integer
Public wMilliseconds As Integer
End Structure
Public Structure WIN32_FIND_DATA
Public dwFileAttributes As Integer
Public ftCreationTime As FILETIME
Public ftLastAccessTime As FILETIME
Public ftLastWriteTime As FILETIME
Public nFileSizeHigh As Integer
Public nFileSizeLow As Integer
Public dwReserved0 As Integer
Public dwReserved1 As Integer
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=260)> Public cFileName As String
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=14)> Public cAlternate As String
End Structure
Private m_ListeFichiers As Collection
'------------------------------
'Constructeur
'------------------------------
Public Sub New()
m_ListeFichiers = New Collection
End Sub
'------------------------------------------------
'Completer une chaine de caracteres par la droite
' Texte: chaine à compléter
' Taille: taille que la chaine doit atteindre
' Caractere: caractere de completion
' Retour: chaine complétée à droite
'------------------------------------------------
Private Function CompleterDroite(ByVal Texte As String, ByVal Taille As Integer, Optional ByVal Caractere As String = " ")
Dim I As Integer
Dim TexteRetour As String
TexteRetour = Texte
TexteRetour = TexteRetour.Trim()
If TexteRetour.Equals(String.Empty) Then
For I = 0 To Taille - 1
TexteRetour = TexteRetour & Caractere
Next I
ElseIf TexteRetour.Length > Taille Then
TexteRetour = TexteRetour.Substring(0, Taille)
Else
For I = TexteRetour.Length To Taille - 1
TexteRetour = TexteRetour & Caractere
Next I
End If
Return TexteRetour
End Function
'---------------------------------
'Lister les fichiers
'---------------------------------
Public Function EnumFiles(ByVal stServ As String, ByVal stLogin As String, ByVal stPass As String, ByVal stRepFtp As String, ByVal stFicFtp As String)
Dim pData As New WIN32_FIND_DATA
Dim hFind As Integer
Dim lRet As Integer
Dim lgFtp As Integer
Dim lgSession, v As Integer
lgSession = InternetOpen("EnumFiles", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
If lgSession Then
lgFtp = InternetConnect(lgSession, stServ, INTERNET_DEFAULT_FTP_PORT, stLogin, stPass, INTERNET_SERVICE_FTP, 0, 0)
If lgFtp Then
If FtpSetCurrentDirectory(lgFtp, stRepFtp) Then
pData.cFileName = CompleterDroite("", MAX_PATH, Chr(0))
hFind = FtpFindFirstFile(lgFtp, stFicFtp, pData, 0, 0)
If hFind = 0 Then Exit Function
m_ListeFichiers.Add(EpurFic(Left(pData.cFileName, InStr(1, pData.cFileName, Chr(0), vbBinaryCompare) - 1)))
Do
pData.cFileName = CompleterDroite("", MAX_PATH, Chr(0))
lRet = InternetFindNextFile(hFind, pData) '<<<<<<<< LIGNE QUI POSE PROBLEME
If lRet = 0 Then Exit Do
v = pData.ftLastWriteTime.dwHighDateTime
m_ListeFichiers.Add(EpurFic(Left(pData.cFileName, InStr(1, pData.cFileName, Chr(0), vbBinaryCompare) - 1)))
Loop
InternetCloseHandle(hFind)
Else
MsgBox("Erreur de positionnement dans le répertoire distant!")
End If
Else
MsgBox("Erreur ouverture session FTP, vérifiez l'adresse, le login/pwd.")
End If
Else
MsgBox("Pas de connexion!")
End If
End Function
..... |
Partager