IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Transfert fichier FTP


Sujet :

Macros et VBA Excel

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Décembre 2011
    Messages
    50
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2011
    Messages : 50
    Points : 35
    Points
    35
    Par défaut Transfert fichier FTP
    Bonjour,

    Je vais travailler pour la 1ère fois avec en vba sue le téléchargement d'un fichier FTP vers mon disque local.
    Je vous explique le contexte:
    Je souhaiterai tous les jours télécharger un fichier csv publié sur un serveur FTP mais uniquement le dernier fichier publié.
    Etape1 : se connecter à internet
    Etape2: se connecter au serveur FTP (login + mot de passe)
    Etape3: Sélection du dernier fichier publié
    Etape4: transférer ce fichier sur mon disque C

    J'ai pu lire sur internet qu'il était possible d'automatiser cela.


    merci pour votre aide.

  2. #2
    Expert éminent sénior
    Avatar de Marc-L
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2013
    Messages
    9 468
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2013
    Messages : 9 468
    Points : 18 674
    Points
    18 674
    Par défaut

    Bonjour,

    un peu de lecture

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Décembre 2011
    Messages
    50
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2011
    Messages : 50
    Points : 35
    Points
    35
    Par défaut pb: connexiion FTP
    Bonjour,
    Voici mon code bien sûr, j'ai modifié le nom du serveur.
    J'arrive bien à me connecter à internet mais pas au serveur FTP la valeur est 0.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    '-------------------
    'Déclaration des API
    '-------------------
    Private Declare Function InternetCloseHandle Lib "wininet.dll" _
      (ByVal hInet As Long) As Integer
     
    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 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
     
    'Envoi et réception d'un fichier
    Private Sub ftp()
    Dim HwndConnect As Long
    Dim HwndOpen As Long
    'Ouvre internet
    HwndOpen = InternetOpen("Microsoft Internet Explorer", 0, vbNullString, vbNullString, 0)
    If HwndOpen = 0 Then
        MsgBox "connection internet impossible"
        Exit Sub
        End If
    'Connection au site ftp
    HwndConnect = InternetConnect(HwndOpen, "FTP.com", "21", "LOGIN", "PASSWORD", 1, 0, 0)
        If HwndConnect = 0 Then
        MsgBox "connection au site " & "FTP" & " impossible"
        Exit Sub
        End If
    MsgBox HwndConnect
    'positionnement du curseur dans le répertoire
     
    FtpSetCurrentDirectory HwndConnect, "ftp.com"
     'Téléchargement
    FtpGetFile HwndConnect, "Fichier1", "Fichier2", _
      False, 0, &H0, 0
     
    InternetCloseHandle HwndConnect 'Ferme la connection
    InternetCloseHandle HwndOpen 'Ferme internet
     
    End Sub

Discussions similaires

  1. transfert fichier ftp
    Par toutou2000 dans le forum C#
    Réponses: 3
    Dernier message: 01/07/2009, 11h48
  2. transfert fichier ftp
    Par Eskarina43 dans le forum Oracle
    Réponses: 2
    Dernier message: 13/11/2006, 08h32
  3. Script transfert fichier ftp
    Par donny dans le forum Linux
    Réponses: 1
    Dernier message: 20/09/2006, 09h02
  4. Transfert fichier par FTP
    Par j_bolduc dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 23/11/2005, 19h59
  5. [] [Réseau] Transfert fichier sur un FTP
    Par CYFL dans le forum VB 6 et antérieur
    Réponses: 5
    Dernier message: 26/02/2003, 17h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo