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

Vos Contributions VBScript Discussion :

[VBS] Retour d'un UPLOAD FTP [Sources]


Sujet :

Vos Contributions VBScript

  1. #1
    Rédacteur

    Profil pro
    Inscrit en
    Avril 2004
    Messages
    94
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 94
    Points : 448
    Points
    448
    Par défaut [VBS] Retour d'un UPLOAD FTP
    Bonjour,

    J'ai un script qui à la fin de son traitement envoi un fichier excel sur un serveur FTP.

    J'utilise donc le code suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    WSHShell.Run "ftp.exe -s:" & FicTemp, 0 , True
    Dans le fichier Temp se trouve les commandes FTP (open->login->pass->PUT).
    Mon problème est que parfois il y a un souci pendant le transfert (réseau ou mémoire tampon...) ce qui fait que mon fichier Excel devient illisible.

    Comment puis je tester la bonne exécution de l'UPLOAD ?
    Est il possible de récupérer la sortie (comme ce qui s'écrit en mode invite de commande par exemple) ?

    Pour info, j'utilise Run plutôt que Exec car je n'ai pas trouvé comment "cacher" l'exécution avec Exec (exécution silencieuse).

    Merci.

  2. #2
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 038
    Points
    20 038
    Par défaut
    J'ai pas trop d'idée .. ce soir..

    tu peu passer par un .bat :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    WSHShell.Run "envoi.bat", 0 , True
    envoi.bat
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ftp -s:envoi.ftp > liste.txt
    puis tu relis le fichier liste.txt...

  3. #3
    Rédacteur

    Profil pro
    Inscrit en
    Avril 2004
    Messages
    94
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 94
    Points : 448
    Points
    448
    Par défaut
    Citation Envoyé par bbil Voir le message
    J'ai pas trop d'idée .. ce soir..

    tu peu passer par un .bat :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    WSHShell.Run "envoi.bat", 0 , True
    envoi.bat
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ftp -s:envoi.ftp > liste.txt
    puis tu relis le fichier liste.txt...
    Merci pour ton info.

    J'aurais préféré resté en VBscript mais comme cette solution marche, je vais partir la dessus.

    Je trouve bien les lignes de retour dans le fichier
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    ...
    150 Ok to send data.
    226 File receive OK.
    ftp : 6185 octets envoy‚s en 0,00 secondes … 6185000,00 Ko/sec.
    Me reste plus qu'a lire le ichier derriere l'éxécution du .bat.

  4. #4
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 038
    Points
    20 038
    Par défaut
    Bonsoir,

    l'on peu se passer du .bat :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Dim WshShell
    Set WshShell = CreateObject("WScript.Shell")
    WSHShell.Run "cmd /c ftp -s:envoi.ftp > result.txt" , 0 , True
    PS : bodbod .. à l'occasion si tu fini par écrire une fonction .vbs d'envoi de fichier (par exemple en générant le fichier script ftp..) puis en lisant le résultat..
    cela pourrai devenir une bonne contribution

  5. #5
    Rédacteur

    Profil pro
    Inscrit en
    Avril 2004
    Messages
    94
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 94
    Points : 448
    Points
    448
    Par défaut
    Citation Envoyé par bbil Voir le message
    Bonsoir,

    l'on peu se passer du .bat :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Dim WshShell
    Set WshShell = CreateObject("WScript.Shell")
    WSHShell.Run "cmd /c ftp -s:envoi.ftp > result.txt" , 0 , True
    PS : bodbod .. à l'occasion si tu fini par écrire une fonction .vbs d'envoi de fichier (par exemple en générant) le fichier script..) puis en lisant le résultat..
    cela pourrai devenir une bonne contribution
    Il me semble avoir essayer cela sans succès. Mais je vais retester avec un mini code (non intégré avec le reste de mon code).

    Bien vu, j'avais effectivement l'intention de mettre cela dans une fonction (génération du fichier de commande, puis envoi, puis controle).

    Je vais voir cela d'ici quelques jours.

  6. #6
    Rédacteur

    Profil pro
    Inscrit en
    Avril 2004
    Messages
    94
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 94
    Points : 448
    Points
    448
    Par défaut
    Citation Envoyé par bbil Voir le message
    Bonsoir,

    l'on peu se passer du .bat :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Dim WshShell
    Set WshShell = CreateObject("WScript.Shell")
    WSHShell.Run "cmd /c ftp -s:envoi.ftp > result.txt" , 0 , True
    PS : bodbod .. à l'occasion si tu fini par écrire une fonction .vbs d'envoi de fichier (par exemple en générant le fichier script ftp..) puis en lisant le résultat..
    cela pourrai devenir une bonne contribution
    Bon j'ai retesté calmement avec un fichier de commande OK.
    Effectivement ca marche nickel depuis VBS avec la commande suivante (il faut appeller cmd et non ftp directement)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    WSHShell.Run "cmd /c ftp.exe -s:" & FicTemp & " > retour.txt", 0 , True
    Me reste plus qu'a coder la mini fonction pour contrôler le fichier de retour.

    Merci bbil

    J'essai de vous faire une petite fonction d'envoi+controle la semaine prochaine

  7. #7
    Rédacteur

    Profil pro
    Inscrit en
    Avril 2004
    Messages
    94
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 94
    Points : 448
    Points
    448
    Par défaut
    Bon, j'ai commencé a ecrire la petite fonction.

    Mais comme dans le topic suivant, j'ai un souci avec le SHELL a l'interieur d'une fonction (function).

    Lorsque j'insère le code dans un SUB, ca marche nickel mais je ne peux pas avoir de valeur de retour indiquant le résultat du transfert.
    Lorsque je le mets dans une fonction, j'ai bien un True/False mais le shell ne fonctionne plus (donc toujours False).

    Le FTP ne fonctionne pas :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Function Function_UploadByFTP(ByVal FichierLocal, ByVal Repertoire, ByVal FichierFTP, ByRef Retour)
    [...]
    Écriture du fichier de commande FTP
    [...]
        Set WSHShell = CreateObject("WScript.Shell")	
        WSHShell.Run "cmd /c ftp.exe -s:" & FichierCommandeFTP & " > " & FichierRetourFTP, 0 , True   
    [...]
    Vérification du fichier de retour
    [...]
    End Function
    Ce code fonctionne mais je ne peux pas avoir de retour True/False
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Sub Sub_UploadByFTP(ByVal FichierLocal, ByVal Repertoire, ByVal FichierFTP, ByRef Retour)
    [...]
    Écriture du fichier de commande FTP
    [...]
        Set WSHShell = CreateObject("WScript.Shell")	
        WSHShell.Run "cmd /c ftp.exe -s:" & FichierCommandeFTP & " > " & FichierRetourFTP, 0 , True   
    [...]
    Vérification du fichier de retour
    [...]
    End Sub

  8. #8
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 038
    Points
    20 038
    Par défaut
    bonsoir,

    je n'ai pas soucis, avec les fonctions, n'as tu pas un code de transfert un peu plus avancé, voir si je vois un problème dans ton code..?

    tiens voilà un début ... :
    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
    Dim oFso 'J'utilise un objet Global oFso ...
    Const ForReading = 1, ForWriting = 2 
    Set oFso = CreateObject("Scripting.FileSystemObject")
     
     
    Dim Retour
    Wscript.Echo UploadByFTP ("MonFichier", "MonRep","FichieFtp", Retour)
    Wscript.Echo Retour
     
    Function UploadByFTP(ByVal FichierLocal, ByVal Repertoire, ByVal FichierFTP, ByRef Retour)
      Dim  fFtpScript
      Dim  fRetour 'Fichier retour
      Dim  stFicRet 'Lecture fichier retour
      Dim  FichierCommandeFTP 'Nom complet du fichier script
      Dim  FichierRetourFTP   
      Dim  stScript ' Script
      Retour = "------" & Now & "------------" & vbCrlf
      FichierCommandeFTP = FicTemp 'Détermine un nom de fichier temporaire pour le script
      FichierRetourFTP   = FicTemp 'Détermine nom du fichier retour
      'Création fichier script ftp 
      set fFtpScript =  oFso.OpenTextFile(FichierCommandeFTP, ForWriting,true)
      stScript =  "?" & vbCrlf & "bye"
      fFtpScript.write stScript
      fFtpScript.close
      Retour = Retour & stScript & vbCrlf & "----------------------------" & vbCrlf 
      Set WSHShell = CreateObject("WScript.Shell")
      WSHShell.Run "cmd /c ftp.exe -s:" & FichierCommandeFTP & " > " & FichierRetourFTP, 0 , True   
      set fRetour = oFso.OpenTextFile(FichierRetourFTP, ForReading,true)
      stFicRet = fRetour.ReadAll
      fRetour.close
      Retour = Retour & stFicRet
      oFso.DeleteFile FichierCommandeFTP 'Efface le fichier script temporaire
      oFso.DeleteFile FichierRetourFTP 'Efface le fichier script temporaire
      UploadByFTP = true
    End Function
     
     
    '
    ' Fonction FicTemp : renvoi le nom d'un fichier temporaire
    '
    Function FicTemp ' as string ..
    dim oFldTemp
    Const TemporaryFolder = 2
    set oFldTemp =  ofso.GetSpecialFolder(TemporaryFolder)
     FicTemp = oFldTemp.path & "\" & oFso.GetTempName
    End Function

  9. #9
    Rédacteur

    Profil pro
    Inscrit en
    Avril 2004
    Messages
    94
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 94
    Points : 448
    Points
    448
    Par défaut
    Citation Envoyé par bbil Voir le message
    bonsoir,

    je n'ai pas soucis, avec les fonctions, n'as tu pas un code de transfert un peu plus avancé, voir si je vois un problème dans ton code..?

    tiens voilà un début ... :
    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
    Dim oFso 'J'utilise un objet Global oFso ...
    Const ForReading = 1, ForWriting = 2 
    Set oFso = CreateObject("Scripting.FileSystemObject")
     
     
    Dim Retour
    Wscript.Echo UploadByFTP ("MonFichier", "MonRep","FichieFtp", Retour)
    Wscript.Echo Retour
     
    Function UploadByFTP(ByVal FichierLocal, ByVal Repertoire, ByVal FichierFTP, ByRef Retour)
      Dim  fFtpScript
      Dim  fRetour 'Fichier retour
      Dim  stFicRet 'Lecture fichier retour
      Dim  FichierCommandeFTP 'Nom complet du fichier script
      Dim  FichierRetourFTP   
      Dim  stScript ' Script
      Retour = "------" & Now & "------------" & vbCrlf
      FichierCommandeFTP = FicTemp 'Détermine un nom de fichier temporaire pour le script
      FichierRetourFTP   = FicTemp 'Détermine nom du fichier retour
      'Création fichier script ftp 
      set fFtpScript =  oFso.OpenTextFile(FichierCommandeFTP, ForWriting,true)
      stScript =  "?" & vbCrlf & "bye"
      fFtpScript.write stScript
      fFtpScript.close
      Retour = Retour & stScript & vbCrlf & "----------------------------" & vbCrlf 
      Set WSHShell = CreateObject("WScript.Shell")
      WSHShell.Run "cmd /c ftp.exe -s:" & FichierCommandeFTP & " > " & FichierRetourFTP, 0 , True   
      set fRetour = oFso.OpenTextFile(FichierRetourFTP, ForReading,true)
      stFicRet = fRetour.ReadAll
      fRetour.close
      Retour = Retour & stFicRet
      oFso.DeleteFile FichierCommandeFTP 'Efface le fichier script temporaire
      oFso.DeleteFile FichierRetourFTP 'Efface le fichier script temporaire
      UploadByFTP = true
    End Function
     
     
    '
    ' Fonction FicTemp : renvoi le nom d'un fichier temporaire
    '
    Function FicTemp ' as string ..
    dim oFldTemp
    Const TemporaryFolder = 2
    set oFldTemp =  ofso.GetSpecialFolder(TemporaryFolder)
     FicTemp = oFldTemp.path & "\" & oFso.GetTempName
    End Function
    Si si j'ai bien un code a donner.
    Je ne l'ai pas mis car je voulais me concentré sur ce qui ne marche pas.
    Encore une fois, si je remplace Function par Sub ca marche (sauf le retour)
    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
    If UploadByFTP("C:\MonFichierLocal.txt" , "www/rep" , "FichierFTP.txt") Then
    	Msgbox "Upload OK"
    Else
    	Msgbox "problème lors du transfert"
    End If
     
    Function UploadByFTP(ByVal FichierLocal, ByVal Repertoire, ByVal FichierFTP)
        Const ForReading = 1, ForWriting = 2, ForAppending = 8
        Dim fso, f_cmd, f_ret
     
        FichierCommandeFTP = "Cmdftp.ftp"
        FichierRetourFTP = "return.txt"
     
        FTP = "ftp.site.com"
        Login = "user"
        Pass = "pass"
     
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set f_cmd = fso.OpenTextFile(FichierCommandeFTP, ForWriting, True)	
        f_cmd.Write "OPEN " & FTP & vbCrLf
        f_cmd.Write "USER " & Login & vbCrLf & Pass & vbCrLf
        f_cmd.Write "cd " & Repertoire & vbCrLf
        f_cmd.Write "put " & FichierLocal & " " & FichierFTP & vbCrLf
        f_cmd.Write "quit"
        f_cmd.Close
     
    	Set WSHShell = CreateObject("WScript.Shell")	
        WSHShell.Run "cmd /c ftp.exe -s:" & FichierCommandeFTP & " > " & FichierRetourFTP, 0 , True
     
        UploadByFTP = False
        Set f_ret = fso.OpenTextFile(FichierRetourFTP, ForReading)
    	while Not f_ret.AtEndOfStream And UploadByFTP = False
    		iF Trim(f_ret.ReadLine) = "226 File receive OK." Then
    			UploadByFTP = True
    		End If
        Wend
        f_ret.close
        fso.DeleteFile FichierCommandeFTP
        fso.DeleteFile FichierRetourFTP
        Set WSHShell = Nothing
        Set fso      = Nothing
        Set f_cmd    = Nothing
        Set f_ret    = Nothing
    End Function

  10. #10
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 038
    Points
    20 038
    Par défaut
    ton code marche, je viens de le tester sur le serveur ftp de dvp.

    j'ai du modifier le script ftp en supprimant la commande user :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    ..    f_cmd.Write "OPEN " & FTP & vbCrLf
        f_cmd.Write Login & vbCrLf & Pass & vbCrLf
        f_cmd.Write "cd " & Repertoire & vbCrLf
    ...
    script ftp :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    OPEN bbil.developpez.com
    xLog
    XXXXX
    cd articles
    put C:\tmp\fichier1.txt FichierFTP.txt
    quit
    pour le retour j'ai :
    ftp> put C:\tmp\fichier1.txt FichierFTP.txt
    200 PORT command successful.
    150 Opening ASCII mode data connection.
    226 Transfer completed.
    ftp : 191 octets envoyés en 0,00 secondes à 191000,00 Ko/sec.
    ftp> quit
    221 Goodbye.
    j'ai modifié ta ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if Trim(f_ret.ReadLine) = "226 File receive OK." Then
    en
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    		if Left(f_ret.ReadLine,4) = "226 " Then

  11. #11
    Rédacteur

    Profil pro
    Inscrit en
    Avril 2004
    Messages
    94
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 94
    Points : 448
    Points
    448
    Par défaut
    Ah ben oui, ca marche.
    Décidément, j'ai un peu de mal en ce moment

    Pour les modifs que tu propose :
    Au taf, le FTP du client me demande le USER devant le login mais effectivement, mon hébergement chez OVH n'en a pas besoin. Bref, c'est un détail.

    Concernant l'autre modification, le LEFT est plus rapide que le Trim ?
    Sinon, j'avais aussi penser a InStr().

    Ci-dessous, voici donc mes fonction GET/PUT/LIST sur FTP
    Ils tiennent de ton code avec les fichiers temporaires.
    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
    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
     
    If UploadByFTP("test.xls" , "www/pro" , "test.xls")  Then
    	Msgbox "Upload du fichier OK"
    Else
    	Msgbox "probleme"
    End If
     
    If GetListFTP( "www/pro","listftp.txt")  Then
    	Msgbox "Liste du repertoire OK"
    Else
    	Msgbox "probleme"
    End If
     
    If DownloadByFTP("test.xls" , "www/pro" , "test2.xls")  Then
    	Msgbox "Download OK"
    Else
    	Msgbox "probleme"
    End If
     
     
    Function UploadByFTP(ByVal FichierLocal, ByVal Repertoire, ByVal FichierFTP)
        Const ForReading = 1, ForWriting = 2, ForAppending = 8
        Dim fso, f_cmd, f_ret
     
        FTP = "ftp.site.com"
        Login = "login"
        Pass = "pass"
     
        Set fso = CreateObject("Scripting.FileSystemObject")
     
        FichierCommandeFTP = fso.GetSpecialFolder(2).path & "\" & fso.GetTempName
        FichierRetourFTP = fso.GetSpecialFolder(2).path & "\" & fso.GetTempName
     
        Set f_cmd = fso.OpenTextFile(FichierCommandeFTP, ForWriting, True)	
        f_cmd.Write "OPEN " & FTP & vbCrLf
        f_cmd.Write "" & Login & vbCrLf & Pass & vbCrLf
        f_cmd.Write "cd " & Repertoire & vbCrLf
        f_cmd.Write "put " & FichierLocal & " " & FichierFTP & vbCrLf
        f_cmd.Write "quit"
        f_cmd.Close
     
    	Set WSHShell = CreateObject("WScript.Shell")	
        WSHShell.Run "cmd /c ftp.exe -s:" & FichierCommandeFTP & " > " & FichierRetourFTP, 0 , True
     
        UploadByFTP = False
        Set f_ret = fso.OpenTextFile(FichierRetourFTP, ForReading)
    	while Not f_ret.AtEndOfStream And UploadByFTP = False
    		iF Left(f_ret.ReadLine,4) = "226 " Then
    			UploadByFTP = True
    		End If
        Wend
        f_ret.close
     
        fso.DeleteFile FichierCommandeFTP
        fso.DeleteFile FichierRetourFTP
     
        Set WSHShell = Nothing
        Set fso      = Nothing
        Set f_cmd    = Nothing
        Set f_ret    = Nothing
    End Function
     
    Function DownloadByFTP(ByVal FichierFTP, ByVal Repertoire, ByVal FichierLocal)
        Const ForReading = 1, ForWriting = 2, ForAppending = 8
        Dim fso, f_cmd, f_ret
     
        FTP = "ftp.site.com"
        Login = "login"
        Pass = "pass"
     
        Set fso = CreateObject("Scripting.FileSystemObject")
     
        FichierCommandeFTP = fso.GetSpecialFolder(2).path & "\" & fso.GetTempName
        FichierRetourFTP = fso.GetSpecialFolder(2).path & "\" & fso.GetTempName
     
        Set f_cmd = fso.OpenTextFile(FichierCommandeFTP, ForWriting, True)	
        f_cmd.Write "OPEN " & FTP & vbCrLf
        f_cmd.Write "" & Login & vbCrLf & Pass & vbCrLf
        f_cmd.Write "CD " & Repertoire & vbCrLf
        f_cmd.Write "GET " & FichierFTP & " " & FichierLocal & vbCrLf
        f_cmd.Write "quit"
        f_cmd.Close
     
    	Set WSHShell = CreateObject("WScript.Shell")	
        WSHShell.Run "cmd /c ftp.exe -s:" & FichierCommandeFTP & " > " & FichierRetourFTP, 0 , True
     
        DownloadByFTP = False
        Set f_ret = fso.OpenTextFile(FichierRetourFTP, ForReading)
    	while Not f_ret.AtEndOfStream And DownloadByFTP = False
    		iF Left(f_ret.ReadLine,4) = "226 " Then
    			DownloadByFTP = True
    		End If
        Wend
        f_ret.close
     
        fso.DeleteFile FichierCommandeFTP
        fso.DeleteFile FichierRetourFTP
     
        Set WSHShell = Nothing
        Set fso      = Nothing
        Set f_cmd    = Nothing
        Set f_ret    = Nothing
    End Function
     
    Function GetListFTP(ByVal Repertoire,ByVal FichierListe)
        Const ForReading = 1, ForWriting = 2, ForAppending = 8
        Dim fso, f_cmd, f_ret
     
        FTP = "ftp.site.com"
        Login = "login"
        Pass = "pass"
     
        Set fso = CreateObject("Scripting.FileSystemObject")
     
        FichierCommandeFTP = fso.GetSpecialFolder(2).path & "\" & fso.GetTempName
        FichierRetourFTP = fso.GetSpecialFolder(2).path & "\" & fso.GetTempName
     
        Set f_cmd = fso.OpenTextFile(FichierCommandeFTP, ForWriting, True)	
        f_cmd.Write "OPEN " & FTP & vbCrLf
        f_cmd.Write "" & Login & vbCrLf & Pass & vbCrLf
        f_cmd.Write "cd " & Repertoire & vbCrLf
        f_cmd.Write "ls * " & FichierLocal & " " & FichierListe & vbCrLf
        f_cmd.Write "quit"
        f_cmd.Close
     
        Set WSHShell = CreateObject("WScript.Shell")	
        WSHShell.Run "cmd /c ftp.exe -s:" & FichierCommandeFTP & " > " & FichierRetourFTP, 0 , True
     
        GetListFTP = False
        Set f_ret = fso.OpenTextFile(FichierRetourFTP, ForReading)
    	while Not f_ret.AtEndOfStream And GetListFTP = False
    		iF Left(f_ret.ReadLine,4) = "226 " Then
    			GetListFTP = True
    		End If
        Wend
        f_ret.close
     
        fso.DeleteFile FichierCommandeFTP
        fso.DeleteFile FichierRetourFTP
     
        Set WSHShell = Nothing
        Set fso      = Nothing
        Set f_cmd    = Nothing
        Set f_ret    = Nothing
    End Function

  12. #12
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 038
    Points
    20 038
    Par défaut


    non le left c'était juste que la réponse de mon serveur n'était pas la même que pour le tiens..:

    226 Transfer completed.
    au lieu de
    226 File receive OK.
    j'ai donc limité le test au 4° caractères .. , pour le Trim , je n'en avais pas besoin car pas d'espace avant le 226 , faut voir si c'est pareil pour ton serveur ..

  13. #13
    Rédacteur

    Profil pro
    Inscrit en
    Avril 2004
    Messages
    94
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 94
    Points : 448
    Points
    448
    Par défaut
    Citation Envoyé par bbil Voir le message


    non le left c'était juste que la réponse de mon serveur n'était pas la même que pour le tiens..:


    au lieu de


    j'ai donc limité le test au 4° caractères .. , pour le Trim , je n'en avais pas besoin car pas d'espace avant le 226 , faut voir si c'est pareil pour ton serveur ..
    OK donc il faut mieux garder "226 " car ce début de message doit être plus générique.

  14. #14
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    j'ai donc limité le test au 4° caractères .. , pour le Trim , je n'en avais pas besoin car pas d'espace avant le 226 , faut voir si c'est pareil pour ton serveur ..
    Dans tous les cas un Trim ne devrait pas faire de mal même s'il n'y a pas d'espace non ?
    Juste par mesure de sécurité.
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  15. #15
    Rédacteur

    Profil pro
    Inscrit en
    Avril 2004
    Messages
    94
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 94
    Points : 448
    Points
    448
    Par défaut
    Citation Envoyé par ced600 Voir le message
    Dans tous les cas un Trim ne devrait pas faire de mal même s'il n'y a pas d'espace non ?
    Juste par mesure de sécurité.
    Oui je pense que je vais ajouter le TRIM.

    Par contre, je suis de nouveau confronté aux problemes cité plus haut (shell dans fonction).

    En fait, mon VBS fonctionne lorsque je le lance (FTP OK), mais lorsque je passe par les "taches planifiées" windows, mon script plante sur le shell et n'ecrit pas le fichier de retour (fichier commande est OK).

    Un probleme d'autorisation ?

  16. #16
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    possible.
    Cela plante à la création de l'objet shell ou au niveau du run ?
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  17. #17
    Rédacteur

    Profil pro
    Inscrit en
    Avril 2004
    Messages
    94
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 94
    Points : 448
    Points
    448
    Par défaut
    Citation Envoyé par ced600 Voir le message
    possible.
    Cela plante à la création de l'objet shell ou au niveau du run ?
    En fait, je n'ai pas de message d'erreur mais le RUN ne dure qu'une fraction de seconde (au lieu du temps de téléchargement) et cela me crée le fichier FTP vide. De plus, le fichier de retour FTP n'est pas crée.

  18. #18
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    ok alors peut être que tout simplement la commande ""cmd /c ftp.exe -s:" & FichierCommandeFTP & " > " & FichierRetourFTP" ne fonctionne pas correctement dans "taches planifiées".

    Crée un fichier .bat avec dedans la commande en statique (sans variable avec un exemple de leur valeur).
    Et dans les traches planifiées de window, planifie un lancement du .bat comme tu le fait pour le .vbs

    Si cela fonctionne pas alors cela vient de l'exécution via une tache planifiée.

    Dans ta commande remplace /c par /k, /k ordonne à cmd de ne pas se fermer après exécution de la commande. Donc s'il y a une erreur ecrite dans la console tu pourras la voir.

    Heu au fait pkoi le sujet est dans ce sous forum, et non dans le forum supérieur ?
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  19. #19
    Rédacteur

    Profil pro
    Inscrit en
    Avril 2004
    Messages
    94
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 94
    Points : 448
    Points
    448
    Par défaut
    Citation Envoyé par ced600 Voir le message
    ok alors peut être que tout simplement la commande ""cmd /c ftp.exe -s:" & FichierCommandeFTP & " > " & FichierRetourFTP" ne fonctionne pas correctement dans "taches planifiées".

    Crée un fichier .bat avec dedans la commande en statique (sans variable avec un exemple de leur valeur).
    Et dans les traches planifiées de window, planifie un lancement du .bat comme tu le fait pour le .vbs

    Si cela fonctionne pas alors cela vient de l'exécution via une tache planifiée.

    Dans ta commande remplace /c par /k, /k ordonne à cmd de ne pas se fermer après exécution de la commande. Donc s'il y a une erreur ecrite dans la console tu pourras la voir.

    Heu au fait pkoi le sujet est dans ce sous forum, et non dans le forum supérieur ?
    Du nouveau.

    En fait, mes script etait placés sur le reseau.
    En deplacant le dossier en local, la tache planifiée semble fonctionnée.

    Peut etre une histoire d'autorisation.

  20. #20
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    que valent FichierCommandeFTP et FichierRetourFTP ?
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

Discussions similaires

  1. Réponses: 19
    Dernier message: 20/04/2014, 04h19
  2. [VBS] Upload FTP
    Par kevain_09 dans le forum VBScript
    Réponses: 6
    Dernier message: 23/12/2006, 14h45
  3. [Upload] Upload ftp free
    Par joquetino dans le forum Langage
    Réponses: 9
    Dernier message: 09/10/2005, 03h28
  4. [Image]Vérifier taille image lors d'upload FTP
    Par MiJack dans le forum Bibliothèques et frameworks
    Réponses: 5
    Dernier message: 10/09/2004, 02h10

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