source: trunk/xftp/xftp.vbs@ 40

Last change on this file since 40 was 40, checked in by marrucho, 11 years ago

mount.bat monte w:
xftp.bat monte f:
le planificateur de taches lance xft-autre.bat qui lance xftp.bat qui lance xftp.vbs

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