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

VBScript Discussion :

Recuperer Fichier via fonction mget en VBS


Sujet :

VBScript

  1. #1
    Membre à l'essai
    Inscrit en
    Mai 2010
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 26
    Points : 15
    Points
    15
    Par défaut Recuperer Fichier via fonction mget en VBS
    Bonjour,

    J'ai la fonction ci-dessous qui permet de récupérer des fichiers d'un serveur FTP vers mon local.
    Mon problème c'est que je voudrais récupérer tous les fichiers qui commencent par une chaine de caractères quelques soit leur extension.

    Avez-vous svp une idée afin que la fonction mget me prenne que les fichiers qui commencent par la chaine de caractère recherché.

    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
    Function FTPDownload(sSite, sUsername, sPassword, sLocalPath, sRemotePath)
      Dim ObjFichier
      Dim yesterday
      Const OpenAsDefault = -2
      Const FailIfNotExist = 0
      Const ForReading = 1
      Const ForWriting = 2
     
      Set oFTPScriptFSO = CreateObject("Scripting.FileSystemObject")
      Set oFTPScriptShell = CreateObject("WScript.Shell")
     
      sRemotePath = Trim(sRemotePath)
      sLocalPath = Trim(sLocalPath)
     
      '----------Path Checks---------
      'Here we will check the remote path, if it contains
      'spaces then we need to add quotes to ensure
      'it parses correctly.
      If InStr(sRemotePath, " ") > 0 Then
        If Left(sRemotePath, 1) <> """" And Right(sRemotePath, 1) <> """" Then
          sRemotePath = """" & sRemotePath & """"
        End If
      End If
     
      'Check to ensure that a remote path was
      'passed. If it's blank then pass a "\"
      If Len(sRemotePath) = 0 Then
        'Please note that no premptive checking of the
        'remote path is done. If it does not exist for some
        'reason. Unexpected results may occur.
        sRemotePath = "\"
      End If
     
      'If the local path was blank. Pass the current
      'working direcory.
      If Len(sLocalPath) = 0 Then
        sLocalpath = oFTPScriptShell.CurrentDirectory
      End If
     
      If Not oFTPScriptFSO.FolderExists(sLocalPath) Then
        'destination not found
        FTPDownload = "Error: Local Folder Not Found."
        Exit Function
      End If
     
      sOriginalWorkingDirectory = oFTPScriptShell.CurrentDirectory
      oFTPScriptShell.CurrentDirectory = sLocalPath
      '--------END Path Checks---------
     
        yesterday = Right(Year(Date),2) & Right("0" & Month(Date),2) & Right("0" & Day(Date() -1),2)
      'build input file for ftp command
      sFTPScript = sFTPScript & "USER " & sUsername & vbCRLF
      sFTPScript = sFTPScript & sPassword & vbCRLF
      sFTPScript = sFTPScript & "cd " & sRemotePath & vbCRLF
      sFTPScript = sFTPScript & "binary" & vbCRLF
      sFTPScript = sFTPScript & "prompt n" & vbCRLF
      sFTPScript = sFTPScript & "mget *" & vbCRLF
      sFTPScript = sFTPScript & "quit" & vbCRLF & "quit" & vbCRLF & "quit" & vbCRLF
     
     
      sFTPTemp = oFTPScriptShell.ExpandEnvironmentStrings("%TEMP%")
      sFTPTempFile = sFTPTemp & "\" & oFTPScriptFSO.GetTempName
      sFTPResults = sFTPTemp & "\" & oFTPScriptFSO.GetTempName
     
      'Write the input file for the ftp command
      'to a temporary file.
      Set fFTPScript = oFTPScriptFSO.CreateTextFile(sFTPTempFile, True)
      fFTPScript.WriteLine(sFTPScript)
      fFTPScript.Close
      Set fFTPScript = Nothing  
     
      oFTPScriptShell.Run "%comspec% /c FTP -n -s:" & sFTPTempFile & " " & sSite & _
      " > " & sFTPResults, 0, TRUE
     
      Wscript.Sleep 1000
     
      'Check results of transfer.
      Set fFTPResults = oFTPScriptFSO.OpenTextFile(sFTPResults, ForReading, _
                        FailIfNotExist, OpenAsDefault)
      sResults = fFTPResults.ReadAll
      fFTPResults.Close
     
      'oFTPScriptFSO.DeleteFile(sFTPTempFile)
      'oFTPScriptFSO.DeleteFile (sFTPResults)
     
      If InStr(sResults, "226 Transfer complete.") > 0 Then
        FTPDownload = True
      ElseIf InStr(sResults, "File not found") > 0 Then
        FTPDownload = "Error: File Not Found"
      ElseIf InStr(sResults, "cannot log in.") > 0 Then
        FTPDownload = "Error: Login Failed."
      Else
        FTPDownload = "Error: Unknown."
      End If
     
      Set oFTPScriptFSO = Nothing
      Set oFTPScriptShell = Nothing
    End Function
     
    Call FTPDownload ("xx.xxx.xxx.xx","xxxxxxx","xxxxxxx","C:\DDDD\YYYY","/AAA/ZZZ/RRR/FFF/RRRR")

  2. #2
    Membre à l'essai
    Inscrit en
    Mai 2010
    Messages
    26
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 26
    Points : 15
    Points
    15
    Par défaut
    Avez-vous une idee svp

Discussions similaires

  1. [XL-2007] Ouverture de fichiers via Fonction
    Par discus23 dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 29/01/2014, 13h45
  2. Réponses: 3
    Dernier message: 27/09/2008, 11h46
  3. recuperer des fichier via le net, et les manipuler en C
    Par sliders_alpha dans le forum Débuter
    Réponses: 12
    Dernier message: 13/09/2008, 12h06
  4. lecture de fichier via une fonction d'analyse
    Par Rniamo dans le forum C++
    Réponses: 2
    Dernier message: 17/07/2008, 16h28
  5. Recupere un fichier via HTTP
    Par kedare dans le forum Entrée/Sortie
    Réponses: 6
    Dernier message: 31/10/2006, 19h13

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