82 lines
2.4 KiB
Plaintext
82 lines
2.4 KiB
Plaintext
Dim shell, fso, scriptsDir, phpExe, logFile
|
|
Set shell = CreateObject("WScript.Shell")
|
|
Set fso = CreateObject("Scripting.FileSystemObject")
|
|
scriptsDir = fso.GetParentFolderName(WScript.ScriptFullName)
|
|
logFile = scriptsDir & "\ftp-server.log"
|
|
|
|
' --- Find PHP ---
|
|
phpExe = ""
|
|
Dim candidates(4)
|
|
candidates(0) = scriptsDir & "\php\php.exe"
|
|
candidates(1) = "C:\xampp\php\php.exe"
|
|
candidates(2) = "C:\php\php.exe"
|
|
candidates(3) = "C:\wamp64\bin\php\php.exe"
|
|
candidates(4) = "C:\wamp\bin\php\php.exe"
|
|
|
|
Dim i
|
|
For i = 0 To 4
|
|
If fso.FileExists(candidates(i)) Then
|
|
phpExe = candidates(i)
|
|
Exit For
|
|
End If
|
|
Next
|
|
|
|
' --- Try WAMP versioned folders ---
|
|
If phpExe = "" Then
|
|
Dim wampBase(1)
|
|
wampBase(0) = "C:\wamp64\bin\php"
|
|
wampBase(1) = "C:\wamp\bin\php"
|
|
Dim w
|
|
For w = 0 To 1
|
|
If fso.FolderExists(wampBase(w)) Then
|
|
Dim subF
|
|
For Each subF In fso.GetFolder(wampBase(w)).SubFolders
|
|
phpExe = subF.Path & "\php.exe"
|
|
Next
|
|
If fso.FileExists(phpExe) Then Exit For
|
|
phpExe = ""
|
|
End If
|
|
Next
|
|
End If
|
|
|
|
If phpExe = "" Then
|
|
On Error Resume Next
|
|
Dim ts
|
|
Set ts = fso.OpenTextFile(logFile, 8, True)
|
|
ts.WriteLine Now & " - ERROR: php.exe not found in any known location"
|
|
ts.Close
|
|
WScript.Quit 1
|
|
End If
|
|
|
|
' --- Skip if already running on port 2121 ---
|
|
Dim portInUse
|
|
portInUse = shell.Run("cmd /c netstat -ano | find "":2121 "" >nul 2>&1", 0, True)
|
|
If portInUse = 0 Then WScript.Quit 0
|
|
|
|
' --- Log start ---
|
|
On Error Resume Next
|
|
Dim ts2
|
|
Set ts2 = fso.OpenTextFile(logFile, 8, True)
|
|
ts2.WriteLine Now & " - Starting FTP server with: " & phpExe
|
|
ts2.Close
|
|
On Error GoTo 0
|
|
|
|
' --- Start FTP server - run from PHP's own directory so extension_dir="ext" resolves correctly ---
|
|
Dim phpDir
|
|
phpDir = fso.GetParentFolderName(phpExe)
|
|
Dim ftpCmd
|
|
ftpCmd = "cmd /c """ & "cd /d """ & phpDir & """ && """ & phpExe & """ -d display_errors=1 -d error_reporting=0 """ & scriptsDir & "\ftp-server.php"" >> """ & logFile & """ 2>&1"""
|
|
shell.Run ftpCmd, 0, False
|
|
|
|
' --- Wait a moment and check it actually started ---
|
|
WScript.Sleep 3000
|
|
portInUse = shell.Run("cmd /c netstat -ano | find "":2121 "" >nul 2>&1", 0, True)
|
|
If portInUse <> 0 Then
|
|
' Failed to start - log and try once more
|
|
Dim ts3
|
|
Set ts3 = fso.OpenTextFile(logFile, 8, True)
|
|
ts3.WriteLine Now & " - WARN: FTP did not start, retrying..."
|
|
ts3.Close
|
|
shell.Run ftpCmd, 0, False
|
|
End If
|