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
| 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 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 FtpSetCurrentDirectory Lib "wininet.dll" Alias _
"FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, _
ByVal lpszDirectory As String) As Boolean
Declare 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
Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" ( _
ByVal hConnect 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
Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Sub offline()
If Sheets("Variables").Range("Q13").Value = "Non" Then MsgBox "Bouton désactivé, contacté le concepteur pour activation !": Exit Sub
MonDossier = ThisWorkbook.Path & "\WEB"
MonDossier2 = ThisWorkbook.Path & "\WEB\empty"
If Dir(MonDossier, vbDirectory) = "" Then
MkDir MonDossier
End If
If Dir(MonDossier2, vbDirectory) = "" Then
MkDir MonDossier2
End If
'COPIE DU FICHIER EN LOCAL
'=========================
succès = False
'PARAMETRES************************
nom_fichier = "viewscorestv.htm"
Fichier = ActiveWorkbook.Path & "\WEB\empty\viewscorestv.htm"
login = "*******"
mot_passe = "*********"
rép = "/www/********/******/"
bin_asc = &H0 '(&H1 ascii, &H2 binaire, &H0 )
Mode = &H8000000 '(&H8000000 mode passif, 0 mode actif)
'**********************************
'Vérifier la connection à internet
InternetOK = InternetOpen("PutFtpFile", 1, "", "", 0)
If InternetOK = 0 Then
MsgBox "connection internet impossible"
Exit Sub
End If
'Vérifier l'accès ftp
Ftp_OK = InternetConnect(InternetOK, "ftp.*********.be", 21, login, mot_passe, 1, Mode, 0)
If Ftp_OK = 0 Then
MsgBox "connection FTP impossible"
Exit Sub
End If
'vérifier le dossier distant
Select_DossierDistant = FtpSetCurrentDirectory(Ftp_OK, rép)
If Select_DossierDistant = 0 Then
MsgBox "impossible de trouver le répertoire distant "
Exit Sub
End If
succès = FtpGetFile(Ftp_OK, nom_fichier, Fichier, False, 0, bin_asc, 0)
If succès Then
'Result = "Le fichier a été correctement récupéré "
'MsgBox Result
résult = "pas de fenêtre svp"
Else
Result = "Erreur FTP : le fichier n'a pas pu être récupéré "
MsgBox Result
End If
'For i = 1 To 7
'récupération des adresses des fichiers à récupérer sur le serveur
'liste_fichier(i) = ThisWorkbook.Worksheets("Envoi FTP").Cells(10 + i, 1).Value
'fichierlocal = cheminFichierSortie & "\" & liste_fichier(i)
'FichierDistant = liste_fichier(i)
'MsgBox "fichier local : " & fichierlocal
'MsgBox "fichier distant : " & FichierDistant
'transfert du fichier
'succès = FtpGetFile(FtpOK, FichierDistant, fichierlocal, False, 0, FTP_TRANSFER_TYPE_ASCII, 0)
'fin affichage fenêtre d'attente
'Waitbox.Hide 'masque la waitbox
'Application.Cursor = xlDefault 'remet le curseur par défaut
'If succès Then
'Result = "Le fichier " & nom_fichier & " a été correctement récupéré "
'MsgBox Result
'Else
'Result = "Erreur FTP : le fichier " & nom_fichier & " n'a pas pu être récupéré."
'MsgBox Result
'ShowError ("GetFile: " & nom_fichier)
'Exit Sub
'End If
'Next
'fermer les pointeurs, ménage
InternetCloseHandle Ftp_OK
InternetCloseHandle Internet_OK
End Sub |
Partager