-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_server.bat
More file actions
204 lines (182 loc) · 4.83 KB
/
run_server.bat
File metadata and controls
204 lines (182 loc) · 4.83 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
@echo off
setlocal EnableExtensions
cd /d "%~dp0"
set "SERVER_CMD=python fileserver.py"
set "MODE="
set "PORT="
set "SHARE_DIR="
set "EXTRA_ARGS="
set "USE_NO_BROWSER=0"
call :print_header
call :check_prerequisites || goto :fatal
if not "%~1"=="" (
echo [INFO] Advanced mode detected. Starting with arguments you provided.
echo [INFO] Command: python fileserver.py %*
echo.
python fileserver.py %*
goto :after_run
)
:menu
echo Choose how you want to run your file server:
echo.
echo [1] Local only (safest) - only this PC can open the server
echo [2] LAN sharing - devices on your Wi-Fi/LAN can open the server
echo [3] Public internet - creates a Cloudflare public link
echo [4] Custom setup (choose mode, port, folder, browser behavior)
echo [5] Show simple examples
echo [0] Exit
echo.
set /p "MENU_CHOICE=Enter your choice (0-5): "
if "%MENU_CHOICE%"=="1" (
set "MODE=local"
goto :launch_selected
)
if "%MENU_CHOICE%"=="2" (
set "MODE=lan"
goto :launch_selected
)
if "%MENU_CHOICE%"=="3" (
set "MODE=public"
goto :launch_selected
)
if "%MENU_CHOICE%"=="4" (
goto :custom_setup
)
if "%MENU_CHOICE%"=="5" (
call :show_examples
goto :menu
)
if "%MENU_CHOICE%"=="0" (
echo.
echo Exiting launcher.
exit /b 0
)
echo.
echo [WARN] Invalid choice. Please type 0, 1, 2, 3, 4, or 5.
echo.
goto :menu
:custom_setup
echo.
echo ================================
echo Custom setup wizard
echo ================================
echo.
set "MODE="
echo Pick mode:
echo [1] local
echo [2] lan
echo [3] public
set /p "CUSTOM_MODE_CHOICE=Mode (1-3, default 2): "
if "%CUSTOM_MODE_CHOICE%"=="" set "CUSTOM_MODE_CHOICE=2"
if "%CUSTOM_MODE_CHOICE%"=="1" set "MODE=local"
if "%CUSTOM_MODE_CHOICE%"=="2" set "MODE=lan"
if "%CUSTOM_MODE_CHOICE%"=="3" set "MODE=public"
if not defined MODE (
echo [WARN] Invalid mode choice. Returning to main menu.
echo.
goto :menu
)
set "PORT="
set /p "PORT=Port (press Enter for default): "
if defined PORT (
for /f "delims=0123456789" %%A in ("%PORT%") do set "PORT_INVALID=1"
if defined PORT_INVALID (
set "PORT_INVALID="
set "PORT="
echo [WARN] Port must contain only numbers. Using default.
)
)
set "SHARE_DIR="
set /p "SHARE_DIR=Folder to share (press Enter for current folder): "
if defined SHARE_DIR (
if not exist "%SHARE_DIR%" (
echo [WARN] Folder does not exist: "%SHARE_DIR%"
echo [WARN] Using current folder instead.
set "SHARE_DIR="
)
)
set "USE_NO_BROWSER=0"
set /p "NO_BROWSER_CHOICE=Do not open browser automatically? (y/N): "
if /i "%NO_BROWSER_CHOICE%"=="y" set "USE_NO_BROWSER=1"
goto :launch_selected
:launch_selected
echo.
echo ================================
echo Starting file server
echo ================================
echo Mode: %MODE%
if defined PORT echo Port: %PORT%
if not defined PORT echo Port: default
if defined SHARE_DIR (
echo Shared folder: "%SHARE_DIR%"
) else (
echo Shared folder: current folder
)
if "%USE_NO_BROWSER%"=="1" (
echo Browser auto-open: disabled
) else (
echo Browser auto-open: enabled
)
if /i "%MODE%"=="public" (
where cloudflared >nul 2>&1
if errorlevel 1 (
echo [WARN] cloudflared is not currently available in PATH.
echo [WARN] Public mode may fail until cloudflared is installed.
)
)
echo.
set "EXTRA_ARGS=--mode %MODE%"
if defined PORT set "EXTRA_ARGS=%EXTRA_ARGS% --port %PORT%"
if defined SHARE_DIR set "EXTRA_ARGS=%EXTRA_ARGS% --directory ""%SHARE_DIR%"""
if "%USE_NO_BROWSER%"=="1" set "EXTRA_ARGS=%EXTRA_ARGS% --no-browser"
echo [INFO] Command: %SERVER_CMD% %EXTRA_ARGS%
echo.
call %SERVER_CMD% %EXTRA_ARGS%
:after_run
if errorlevel 1 (
echo.
echo [ERROR] The server stopped with an error.
echo [TIP] Run setup.bat first if dependencies are missing.
goto :fatal
)
echo.
echo ================================
echo Server process ended normally.
echo ================================
pause
exit /b 0
:check_prerequisites
where python >nul 2>&1
if errorlevel 1 (
echo [ERROR] Python is not installed or not available in PATH.
echo [ACTION] Run setup.bat, then try again.
exit /b 1
)
if not exist fileserver.py (
echo [ERROR] fileserver.py was not found in:
echo %CD%
echo [ACTION] Open this script from the project folder.
exit /b 1
)
exit /b 0
:print_header
echo.
echo =========================================================
echo 63xky File Server Launcher
echo Easy start menu for Local, LAN, or Public sharing
echo =========================================================
echo.
exit /b 0
:show_examples
echo.
echo Simple command examples:
echo python fileserver.py --mode local
echo python fileserver.py --mode lan --port 8080
echo python fileserver.py --mode public --directory ".\files"
echo.
exit /b 0
:fatal
echo.
echo Launcher finished with errors.
pause
exit /b 1