VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Classe_FTP"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit


Public Function Connexion() As Boolean
   
   'flag_Connexion = False
   
   'If FTP_Connection Then InternetCloseHandle (FTP_Connection)
   'FTP_Connection = InternetConnect(FTP_Open, FTP_Site, INTERNET_DEFAULT_FTP_PORT, FTP_Utilisateur, FTP_Password, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0)
   'If FTP_Connection Then flag_Connexion = True

End Function

Public Function DonneRepertoireCourant() As String

   DonneRepertoireCourant = String(255, Chr(0))
   FtpGetCurrentDirectory FTP_Connection, DonneRepertoireCourant, 255
   DonneRepertoireCourant = Left(DonneRepertoireCourant, InStr(DonneRepertoireCourant, Chr(0)) - 1)
   
End Function

Public Function CreeRepertoire(sRepertoire As String) As Boolean

   CreeRepertoire = FtpCreateDirectory(FTP_Connection, sRepertoire)

End Function

Public Function AttribueRepertoireCourant(sRepertoire As String) As Boolean

   AttribueRepertoireCourant = FtpSetCurrentDirectory(FTP_Connection, sRepertoire)

End Function

Public Function UploadFichier(sCheminLocal As String, sNomSurSite As String) As Boolean

   UploadFichier = FtpPutFile(FTP_Connection, sCheminLocal, sNomSurSite, FTP_TRANSFER_TYPE_UNKNOWN, 0)

End Function

Public Function RenommeFichier(sAncienNom As String, sNouveauNom As String) As Boolean

   RenommeFichier = FtpRenameFile(FTP_Connection, sAncienNom, sNouveauNom)

End Function

'Public Sub EnumereFichier(Pdic As Dictionary, sRepertoire As String)

'   Dim pData As WIN32_FIND_DATA
'   Dim lRet As Long
'   Dim hFind As Long
   
'   pData.cFileName = String(260, Chr(0))
'   AttribueRepertoireCourant sRepertoire
'   hFind = FtpFindFirstFile(LhConnection, "*.*", pData, 0, 0)
'   If hFind = 0 Then Exit Sub
 '  Do
  '    pData.cFileName = String(260, Chr(0))
   '   lRet = InternetFindNextFile(hFind, pData)
    '  If lRet = 0 Then Exit Do
   '   If (pData.dwFileAttributes And vbDirectory) = vbDirectory Then
    '     If Left(pData.cFileName, 2) <> ".." And Left(pData.cFileName, 1) <> "." Then
     '       Pdic.Add "?" & sRepertoire & Left(pData.cFileName, InStr(pData.cFileName, Chr(0)) - 1) & "/", Left(pData.cFileName, InStr(pData.cFileName, Chr(0)) - 1)
     '    End If
   '   Else
   '      Pdic.Add sRepertoire & Left(pData.cFileName, InStr(pData.cFileName, Chr(0)) - 1), Left(pData.cFileName, InStr(pData.cFileName, Chr(0)) - 1)
   '   End If
 '  Loop
 '  InternetCloseHandle hFind
   
'End Sub

Public Function DownloadFichier(sNomSurSite As String, sCheminLocal As String) As Boolean

   DownloadFichier = FtpGetFile(FTP_Connection, sNomSurSite, sCheminLocal, False, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0)

End Function

Public Function EffaceFichier(sNomSurSite As String) As Boolean

   EffaceFichier = FtpDeleteFile(FTP_Connection, sNomSurSite)

End Function

Public Function EffaceRepertoire(sRepertoire As String) As Boolean

   EffaceRepertoire = FtpRemoveDirectory(FTP_Connection, sRepertoire)

End Function

Private Sub Class_Initialize()

   FTP_Open = InternetOpen(App.Title, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)

End Sub

Private Sub Class_Terminate()
   
   If FTP_Connection Then InternetCloseHandle (FTP_Connection)
   If FTP_Open Then InternetCloseHandle (FTP_Open)

End Sub

