Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Général VBA
Général VBA Forum général VBA . Pour les logiciels spécifiques (Access, Excel, Word, ...), postez dans les bons sous forums.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 29/06/2006, 12h39   #1
Candidat au titre de Membre du Club
 
Inscription : mai 2006
Messages : 46
Détails du profil
Informations forums :
Inscription : mai 2006
Messages : 46
Points : 11
Points : 11
Par défaut [vba] Probleme Ftp

bonjour,je voudrais savoir si il est possible en vba
de creer un petit programme qui se connecter sur un FTP
avec un login et mot de passe (connue) et qu'il puisse
aller télécharger les fichiers stockés sur ce FTP et les rammenés
sur mon disque dur à un endroit précis style Mes Documents.

Merci et si quelqu'un c'est comment m'aider je veut bien
je cherche aussi de mon coté Merci
noob_vba est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/06/2006, 14h03   #2
Candidat au titre de Membre du Club
 
Inscription : mai 2006
Messages : 46
Détails du profil
Informations forums :
Inscription : mai 2006
Messages : 46
Points : 11
Points : 11
Bonjour j'ai trouver comment envoyer des donners sur un ftp mais je sais toujours pas comment en recuperer si quelqu'un peut m'aider sa serais sympa

Code :
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
Private Sub Envoyer()
    Dim fichToUpload As String
    Dim fichToRename As String
    Dim Clef As String
    Dim RepDestination As String
    Dim i As Byte
    Dim tmpString As String
    Dim ctl As Object
        On Error GoTo err:
        For Each ctl In Me.Controls
            If TypeOf ctl Is CommandButton Then
                ctl.Enabled = False
            End If
        Next
        Screen.MousePointer = 13
        Select Case GetSetting("FTP - Upload backup", "Globals", "Choix de la clé")
        Case 1
            Clef = "xJ57MOs15Qz"
        Case 2
            Clef = "xJ57MOs25Qz"
        Case 3
            Clef = "xJ57MOs35Qz"
        End Select
        With Me.Inet1
            .Protocol = icFTP    'declaration protocole
            tmpString = cr.JustDécrypter(GetSetting("FTP - Upload backup", "FTP", "URL"), Clef)
            .URL = tmpString
            '.URL ="ftp://user:password@ftp.perso.free.fr"
            For i = 1 To NbreFich
                fichToUpload = cr.JustDécrypter(GetSetting("FTP - Upload backup", "Fichiers à envoyer", "Fichier_" & i), Clef)
                If Dir(fichToUpload) = "" Then
                    MsgBox fichToUpload & vbCrLf & "Fichier introuvable !", vbExclamation
                    .Execute , "CLOSE"    ' Ferme la connexion.
                    Do Until .StillExecuting = False    'boucle pendant le traitement de inet
                        DoEvents
                    Loop
                    MsgBox "Reconfigurez SVP, en utilisant le programme normal", vbInformation
                    Unload Me
                End If
                fichToRename = cr.JustDécrypter(GetSetting("FTP - Upload backup", "Fichiers renommés", "Fichier_" & i), Clef)
                If InStr(1, fichToUpload, " ") <> 0 Then
                    'y a espace dans le chemin, faut doubler les ""
                    fichToUpload = """" & fichToUpload & """"
                End If
                If InStr(1, fichToRename, " ") <> 0 Then
                    'y a espace dans le chemin, faut doubler les ""
                    fichToRename = """ & fichToRename & """
                End If
                RepDestination = cr.JustDécrypter(GetSetting("FTP - Upload backup", "FTP", "Répertoire de destination"), Clef)
                tmpString = fichToUpload & " /" & RepDestination & "/" & fichToRename
                .Execute , "PUT " & tmpString
                Do Until .StillExecuting = False    'boucle pendant le traitement de inet
                    DoEvents
                Loop
            Next i
            .Execute , "CLOSE"    ' Ferme la connexion.
            Do Until .StillExecuting = False    'boucle pendant le traitement de inet
                DoEvents
            Loop
        End With
        For Each ctl In Me.Controls
            If TypeOf ctl Is CommandButton Then
                ctl.Enabled = True
            End If
        Next
        Screen.MousePointer = 0
        Exit Sub
err:
        Exit Sub
End Sub
Encore
Merci
noob_vba est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/06/2006, 15h33   #3
Candidat au titre de Membre du Club
 
Inscription : mai 2006
Messages : 46
Détails du profil
Informations forums :
Inscription : mai 2006
Messages : 46
Points : 11
Points : 11
J'ai aussi sa mais sa a pas l'air de marcher au cas ou sa pourrais aider quelqu'un je vous donne ceci

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Cochez "Microsoft Internet Transfer Control" dans les composants du projet. Placez un contôle de ce type sur une form. Son nom par défaut est "Inet1". Le code ci-dessous montre comment l'utiliser pour uploader un fichier :
 
 
vb 
Private Sub CopieParFtp(ByVal source As String, ByVal destination, ByVal login As String, _
                        ByVal motdepasse As String, ByVal url As String)
With Inet1
    .AccessType = icDirect
    .Protocol = icFTP
    .URL = "ftp://" & login & ":" & motdepasse & "@" & url
    .Execute , "SEND " & source & " " & "/" & destination
    While .StillExecuting
        DoEvents
    Wend
    .Cancel
End With
End Sub
 
 
Voici un exemple d'appel à la procédure :
 
 
vb 
CopieParFtp "c:\lettre.txt", "lettre.txt", "bill", "HgDrk62B", "microsoft.com"

En esperant vos réponses ou pouvoir aidez quelqu'un a bientôt

Merci
noob_vba est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/06/2006, 09h28   #4
Candidat au titre de Membre du Club
 
Inscription : mai 2006
Messages : 46
Détails du profil
Informations forums :
Inscription : mai 2006
Messages : 46
Points : 11
Points : 11
Personne n'a une petite idée ok on abandonne tous et on repare sur ce code

Code :
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
Option Compare Database
 
Const FTP_TRANSFER_TYPE_UNKNOWN = &H0
Const FTP_TRANSFER_TYPE_ASCII = &H1
Const FTP_TRANSFER_TYPE_BINARY = &H2
Const INTERNET_DEFAULT_FTP_PORT = 21               ' default for FTP servers
Const INTERNET_SERVICE_FTP = 1
Const INTERNET_FLAG_PASSIVE = &H8000000            ' used for FTP connections
Const INTERNET_OPEN_TYPE_PRECONFIG = 0                    ' use registry configuration
Const INTERNET_OPEN_TYPE_DIRECT = 1                        ' direct to net
Const INTERNET_OPEN_TYPE_PROXY = 3                         ' via named proxy
Const INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4   ' prevent using java/script/INS
Const MAX_PATH = 260
 
Private Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type
 
Private Type WIN32_FIND_DATA
    dwFileAttributes As Long
    ftCreationTime As FILETIME
    ftLastAccessTime As FILETIME
    ftLastWriteTime As FILETIME
    nFileSizeHigh As Long
    nFileSizeLow As Long
    dwReserved0 As Long
    dwReserved1 As Long
    cFileName As String * MAX_PATH
    cAlternate As String * 14
End Type
 
Private Declare Function InternetCloseHandle Lib "wininet" (ByRef hInet 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 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 FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias "FtpGetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszCurrentDirectory As String, lpdwCurrentDirectory As Long) As Long
Private Declare Function FtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpRemoveDirectory Lib "wininet.dll" Alias "FtpRemoveDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean
Private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" (ByVal hFtpSession As Long, ByVal lpszExisting As String, ByVal lpszNew As String) As Boolean
Private 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
Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hConnect As Long, ByVal lpszLocalFile As String, ByVal lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Private Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" (lpdwError As Long, ByVal lpszBuffer As String, lpdwBufferLength As Long) As Boolean
Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (ByVal hFtpSession As Long, ByVal lpszSearchFile As String, lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContent As Long) As Long
Private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long
Const PassiveConnection As Boolean = True
 
Private Sub Form_Load()
    'KPD-Team 2000
    'URL: http://www.allapi.net
    'E-Mail: KPDTeam@allapi.net
    Dim hConnection As Long, hOpen As Long, sOrgPath  As String
    'open an internet connection
    hOpen = InternetOpen("API-Guide sample program", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
    'connect to the FTP server
    hConnection = InternetConnect(hOpen, "your ftp server", INTERNET_DEFAULT_FTP_PORT, "your login", "your password", INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
    'create a buffer to store the original directory
    sOrgPath = String(MAX_PATH, 0)
    'get the directory
    FtpGetCurrentDirectory hConnection, sOrgPath, Len(sOrgPath)
    'create a new directory 'testing'
    FtpCreateDirectory hConnection, "testing"
    'set the current directory to 'root/testing'
    FtpSetCurrentDirectory hConnection, "testing"
    'upload the file 'test.htm'
    FtpPutFile hConnection, "C:\test.htm", "test.htm", FTP_TRANSFER_TYPE_UNKNOWN, 0
    'rename 'test.htm' to 'apiguide.htm'
    FtpRenameFile hConnection, "test.htm", "apiguide.htm"
    'enumerate the file list from the current directory ('root/testing')
    EnumFiles hConnection
    'retrieve the file from the FTP server
    FtpGetFile hConnection, "apiguide.htm", "c:\apiguide.htm", False, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0
    'delete the file from the FTP server
    FtpDeleteFile hConnection, "apiguide.htm"
    'set the current directory back to the root
    FtpSetCurrentDirectory hConnection, sOrgPath
    'remove the direcrtory 'testing'
    FtpRemoveDirectory hConnection, "testing"
    'close the FTP connection
    InternetCloseHandle hConnection
    'close the internet connection
    InternetCloseHandle hOpen
End Sub
Public Sub EnumFiles(hConnection As Long)
    Dim pData As WIN32_FIND_DATA, hFind As Long, lRet As Long
    'set the graphics mode to persistent
    Me.AutoRedraw = True
    'create a buffer
    pData.cFileName = String(MAX_PATH, 0)
    'find the first file
    hFind = FtpFindFirstFile(hConnection, "*.*", pData, 0, 0)
    'if there's no file, then exit sub
    If hFind = 0 Then Exit Sub
    'show the filename
    Me.Print Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
    Do
        'create a buffer
        pData.cFileName = String(MAX_PATH, 0)
        'find the next file
        lRet = InternetFindNextFile(hFind, pData)
        'if there's no next file, exit do
        If lRet = 0 Then Exit Do
        'show the filename
        Me.Print Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
    Loop
    'close the search handle
    InternetCloseHandle hFind
End Sub
Sub ShowError()
    Dim lErr As Long, sErr As String, lenBuf As Long
    'get the required buffer size
    InternetGetLastResponseInfo lErr, sErr, lenBuf
    'create a buffer
    sErr = String(lenBuf, 0)
    'retrieve the last respons info
    InternetGetLastResponseInfo lErr, sErr, lenBuf
    'show the last response info
    MsgBox "Error " + CStr(lErr) + ": " + sErr, vbOKOnly + vbCritical
End Sub
Voila est-ce plus clair ?
noob_vba est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/06/2006, 10h20   #5
Candidat au titre de Membre du Club
 
Inscription : mai 2006
Messages : 46
Détails du profil
Informations forums :
Inscription : mai 2006
Messages : 46
Points : 11
Points : 11
comment savoir si ce petit bout de code marche

hConnection = InternetConnect(hOpen, "your ftp server", INTERNET_DEFAULT_FTP_PORT, "your login", "your password", INTERNET_SERVICE_FTP,

je sais pas si il se connecte ou pas ?

PLz aider moi sa fait 2 jours que je galère
noob_vba est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 00h08.


 
 
 
 
Partenaires

Hébergement Web