File size: 1,151 Bytes
fcb1da1
d9c2e0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from cheroot import wsgi
from wsgidav.wsgidav_app import WsgiDAVApp
from wsgidav.fs_dav_provider import FilesystemProvider

# Create the files directory and sample.txt
files_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "files")
if not os.path.exists(files_dir):
    os.makedirs(files_dir)

# Create a sample.txt file
with open(os.path.join(files_dir, "sample.txt"), "w") as f:
    f.write("This is a sample file for the WebDAV server.")

print(f"Created 'files' directory with sample.txt at {files_dir}")

# Configuration
config = {
    "provider_mapping": {
        "/": FilesystemProvider(files_dir)
    },
    "http_authenticator": {
        "domain_controller": None,
    },
    "simple_dc": {"user_mapping": {"*": True}},  # No authentication
    "verbose": 1,
}

# Create the WSGI application
app = WsgiDAVApp(config)

# Create and start the server
server_addr = "0.0.0.0"
server_port = 7860
server = wsgi.Server((server_addr, server_port), app)

print(f"Starting WebDAV server at http://{server_addr}:{server_port}")
try:
    server.start()
except KeyboardInterrupt:
    print("Stopping server...")
    server.stop()