| 1 | ' 03 mars 2014
|
|---|
| 2 |
|
|---|
| 3 | Option Explicit
|
|---|
| 4 |
|
|---|
| 5 | Dim strComputer, objWMIService, colItems, objItem
|
|---|
| 6 | Dim objWMI, objItems, id
|
|---|
| 7 |
|
|---|
| 8 | Dim PathFileResult
|
|---|
| 9 | PathFileResult="c:\temp\xftpDirResult.txt"
|
|---|
| 10 |
|
|---|
| 11 | Dim PathFileFtpArg
|
|---|
| 12 | PathFileFtpArg="c:\temp\empty.txt"
|
|---|
| 13 |
|
|---|
| 14 | ' force l'execution du script, même si défaut
|
|---|
| 15 | On error resume next
|
|---|
| 16 |
|
|---|
| 17 | Wscript.Echo "xftp :"
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 | 'connexion au serveur ftp et transfert le dossier le plus récent
|
|---|
| 21 | Function ConnectLecteurReseauFtpWithLast()
|
|---|
| 22 | Dim objOutStream, objFile, objFSO, objShell, dirFSO
|
|---|
| 23 | Dim ftpHost, idCond, cmd2Exec, localDir
|
|---|
| 24 |
|
|---|
| 25 | Const ForWriting = 2
|
|---|
| 26 |
|
|---|
| 27 | ' Wscript.echo "ConnectLecteurReseauFtpWithLast"
|
|---|
| 28 |
|
|---|
| 29 | 'lecture lecteur réseau ftp
|
|---|
| 30 | Set objShell = CreateObject("WScript.Shell")
|
|---|
| 31 | ' cmd2Exec = "%comspec% /c dir f: /A:D /O:-D /T:C /B > c:\temp\xftpDirResult.txt"
|
|---|
| 32 | cmd2Exec = "%comspec% /c dir f: /A:D /O:-D /T:C /B > " & PathFileResult
|
|---|
| 33 | Wscript.echo cmd2exec
|
|---|
| 34 | objShell.Run cmd2Exec,0,True
|
|---|
| 35 |
|
|---|
| 36 | 'lecture fichier pour récupérer le dernier idCond
|
|---|
| 37 | Set objFSO = CreateObject("Scripting.FileSystemObject")
|
|---|
| 38 | ' Set objFile = objFSO.OpenTextFile("c:\temp\xftpDirResult.txt",1)
|
|---|
| 39 | Set objFile = objFSO.OpenTextFile(PathFileResult,1)
|
|---|
| 40 | '1ere ligne du fichier
|
|---|
| 41 | idCond=Cint(objFile.ReadLine)
|
|---|
| 42 | ' Wscript.echo idCond
|
|---|
| 43 | objFile.Close
|
|---|
| 44 |
|
|---|
| 45 | ''''' CREER LE REPERTOIRE EN LOCAL SI N'EXISTE PAS '''''
|
|---|
| 46 | Set dirFSO = CreateObject("Scripting.FileSystemObject")
|
|---|
| 47 | localDir = "c:/temp/"&idCond
|
|---|
| 48 | If Not dirFSO.FolderExists(localDir) Then
|
|---|
| 49 | dirFSO.CreateFolder localDir
|
|---|
| 50 | End If
|
|---|
| 51 |
|
|---|
| 52 | 'accès ftp
|
|---|
| 53 | ftpHost = "172.16.1.19"
|
|---|
| 54 | ' Set objOutStream = objFSO.OpenTextFile("C:\temp\"&idCond&"\empty.txt", ForWriting, True)
|
|---|
| 55 | Set objOutStream = objFSO.OpenTextFile(PathFileFtpArg, ForWriting, True)
|
|---|
| 56 | With objOutStream
|
|---|
| 57 | .WriteLine "USER moi" ' utilisateur
|
|---|
| 58 | .WriteLine "PASS toi" ' mdp
|
|---|
| 59 | .WriteLine "ascii"
|
|---|
| 60 | .WriteLine "prompt off"
|
|---|
| 61 | .writeLine "cd "&"temp/json/"&idCond ' il faut aller les chercher dans ce repertoire
|
|---|
| 62 | .WriteLine "lcd "&"c:/temp/"&idCond ' il faut les copier dans ce repertoire
|
|---|
| 63 | .WriteLine "mget *" ' recupere et redate
|
|---|
| 64 | .WriteLine "bye"
|
|---|
| 65 | .Close
|
|---|
| 66 | End With
|
|---|
| 67 | objOutStream.Close
|
|---|
| 68 | 'Set objShell = CreateObject("WScript.Shell")
|
|---|
| 69 | ' cmd2Exec = "%comspec% /c FTP -s:" & "C:\temp\"&idCond&"\empty.txt" & " " & ftpHost
|
|---|
| 70 | cmd2Exec = "%comspec% /c FTP -s:" & PathFileFtpArg & " " & ftpHost
|
|---|
| 71 | Wscript.echo cmd2exec
|
|---|
| 72 | objShell.Run cmd2Exec,0,True
|
|---|
| 73 |
|
|---|
| 74 | ConnectLecteurReseauFtpWithLast=idCond'on retourne la valeur de idCond
|
|---|
| 75 |
|
|---|
| 76 | Wscript.Echo
|
|---|
| 77 | End Function
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 | 'connexion au serveur ftp et transfert le dossier sélectionné
|
|---|
| 81 | Sub ConnectLecteurReseauFtpWithId(byval id)
|
|---|
| 82 | Dim objOutStream, objFSO, objShell, dirFSO
|
|---|
| 83 | Dim ftpHost, cmd2Exec, localDir
|
|---|
| 84 |
|
|---|
| 85 | Const ForWriting = 2
|
|---|
| 86 |
|
|---|
| 87 | ' Wscript.echo "ConnectLecteurReseauFtpWithId"
|
|---|
| 88 |
|
|---|
| 89 | ''''' CREER LE REPERTOIRE EN LOCAL SI N'EXISTE PAS '''''
|
|---|
| 90 | Set dirFSO = CreateObject("Scripting.FileSystemObject")
|
|---|
| 91 | localDir = "c:/temp/"&id
|
|---|
| 92 | If Not dirFSO.FolderExists(localDir) Then
|
|---|
| 93 | dirFSO.CreateFolder localDir
|
|---|
| 94 | End If
|
|---|
| 95 |
|
|---|
| 96 | 'accès ftp
|
|---|
| 97 | ftpHost = "172.16.1.19"
|
|---|
| 98 | Set objFSO = CreateObject("Scripting.FileSystemObject")
|
|---|
| 99 | ' Set objOutStream = objFSO.OpenTextFile("C:\temp\"&id&"\empty.txt", ForWriting, True)
|
|---|
| 100 | Set objOutStream = objFSO.OpenTextFile(PathFileFtpArg, ForWriting, True)
|
|---|
| 101 |
|
|---|
| 102 | With objOutStream
|
|---|
| 103 | .WriteLine "USER moi" ' USERNAME
|
|---|
| 104 | .WriteLine "PASS toi" ' Password
|
|---|
| 105 | .WriteLine "ascii"
|
|---|
| 106 | .WriteLine "prompt off"
|
|---|
| 107 | .writeLine "cd "&"temp/json/"&id
|
|---|
| 108 | .WriteLine "lcd "&"c:/temp/"&id ' FOLDER I'm changing into
|
|---|
| 109 | .WriteLine "mget *" ' Get all files with today's date in it
|
|---|
| 110 | .WriteLine "bye"
|
|---|
| 111 | .Close
|
|---|
| 112 | End With
|
|---|
| 113 | Set objShell = CreateObject("WScript.Shell")
|
|---|
| 114 | ' cmd2Exec = "%comspec% /c FTP -s:" & "C:\temp\"&id&"\empty.txt" & " " & ftpHost
|
|---|
| 115 | cmd2Exec = "%comspec% /c FTP -s:" & PathFileFtpArg & " " & ftpHost
|
|---|
| 116 | Wscript.echo cmd2exec
|
|---|
| 117 | objShell.Run cmd2Exec,0,True
|
|---|
| 118 |
|
|---|
| 119 | Wscript.Echo
|
|---|
| 120 | End Sub
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 | 'Copies sur la borne si w: existe
|
|---|
| 124 | Sub CopieBorne(byval id)
|
|---|
| 125 | Dim dirBorneFSO, objShell
|
|---|
| 126 | Dim cmd2Exec, borneDir
|
|---|
| 127 |
|
|---|
| 128 | Wscript.echo "CopieBorne"
|
|---|
| 129 |
|
|---|
| 130 | Set dirBorneFSO = CreateObject("Scripting.FileSystemObject")
|
|---|
| 131 | borneDir = "w:"
|
|---|
| 132 | If dirBorneFSO.DriveExists(borneDir) Then
|
|---|
| 133 | Wscript.echo "drive w:"
|
|---|
| 134 | Set objShell = CreateObject("WScript.Shell")
|
|---|
| 135 | Wscript.echo "copy xftp.."
|
|---|
| 136 | cmd2Exec = "%comspec% /c copy /Y c:\temp\xftp.txt w:"
|
|---|
| 137 | Wscript.echo cmd2exec
|
|---|
| 138 | objShell.Run cmd2Exec,0,True
|
|---|
| 139 |
|
|---|
| 140 | Wscript.echo "create directory w:\"&id&""
|
|---|
| 141 | cmd2Exec = "%comspec% /c mkdir w:\"&id&""
|
|---|
| 142 | Wscript.echo cmd2exec
|
|---|
| 143 | objShell.Run cmd2Exec,0,True
|
|---|
| 144 | Wscript.echo "error" & " Description:" & Err.Description
|
|---|
| 145 |
|
|---|
| 146 | Wscript.echo "copy into repertory w:\"&id&""
|
|---|
| 147 | cmd2Exec = "%comspec% /c copy /Y c:\temp\"&id&"\* w:\"&id&""
|
|---|
| 148 | Wscript.echo cmd2exec
|
|---|
| 149 | objShell.Run cmd2Exec,0,True
|
|---|
| 150 | Else
|
|---|
| 151 | Wscript.echo "w: do not exist"
|
|---|
| 152 | End If
|
|---|
| 153 |
|
|---|
| 154 | Err.clear
|
|---|
| 155 | Wscript.Echo
|
|---|
| 156 | End Sub
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 | 'recupere la date
|
|---|
| 160 | strComputer = "."
|
|---|
| 161 | Set objWMIService = GetObject("winmgmts:" _
|
|---|
| 162 | & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
|
|---|
| 163 | Set colItems = objWMIService.ExecQuery("Select * from Win32_LocalTime")
|
|---|
| 164 | For Each objItem in colItems
|
|---|
| 165 | Wscript.Echo "" &objItem.Day,"-","" &objItem.Month,"-","" &objItem.Year,_
|
|---|
| 166 | ",","" &objItem.Hour,":","" &objItem.Minute,":","" &objItem.Second
|
|---|
| 167 | Next
|
|---|
| 168 |
|
|---|
| 169 | 'recuperer les adresses ip
|
|---|
| 170 | Set objWMI = getobject("winmgmts:")
|
|---|
| 171 | set objItems = objWMI.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True")
|
|---|
| 172 | For Each objItem In objItems
|
|---|
| 173 | 'Wscript.Echo objItem.IPAddress(0)
|
|---|
| 174 | If Left(objItem.IPAddress(0),3) = "172" Then
|
|---|
| 175 | Wscript.Echo objItem.IPAddress(0), " : ...CONNECTION TO FTP SERVER..."
|
|---|
| 176 | If WScript.Arguments.Length >0 Then
|
|---|
| 177 | Wscript.echo "id conditionning= "&WScript.Arguments(0),"... transfering the selected repertory"'parametre id conditionning
|
|---|
| 178 | ' idCond = WScript.Arguments(0)
|
|---|
| 179 | ConnectLecteurReseauFtpWithId(WScript.Arguments(0))
|
|---|
| 180 | CopieBorne(WScript.Arguments(0))
|
|---|
| 181 | exit for'une seule fois suffit !!
|
|---|
| 182 | Else
|
|---|
| 183 | Wscript.echo "No id conditionning specified... transfering the most recent repertory"
|
|---|
| 184 | id=ConnectLecteurReseauFtpWithLast()
|
|---|
| 185 | CopieBorne(id)
|
|---|
| 186 | exit for'une seule fois suffit !!
|
|---|
| 187 | End If
|
|---|
| 188 | ' Select Case Left(objItem.IPAddress(0),8)
|
|---|
| 189 | ' Case "172.XX.X"
|
|---|
| 190 | ' 'instructions
|
|---|
| 191 | ' Case "172.XX.X"
|
|---|
| 192 | ' 'instructions
|
|---|
| 193 | ' End Select
|
|---|
| 194 | End If
|
|---|
| 195 | If Left(objItem.IPAddress(0),3) = "134" Then
|
|---|
| 196 | Wscript.Echo objItem.IPAddress(0), " : ...NO CONNECTION TO FTP SERVER..."
|
|---|
| 197 | 'ne fait rien
|
|---|
| 198 | Wscript.Echo
|
|---|
| 199 | Wscript.quit
|
|---|
| 200 | End If
|
|---|
| 201 | Next
|
|---|
| 202 | Set objItem = Nothing
|
|---|
| 203 | Set objItems = Nothing
|
|---|
| 204 | Set objWMI = Nothing
|
|---|
| 205 |
|
|---|
| 206 | Wscript.quit
|
|---|