File size: 1,259 Bytes
a051613
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from wsgidav.wsgidav_app import WsgiDAVApp
from wsgidav.fs_dav_provider import FilesystemProvider
from cheroot.wsgi import Server as WSGIServer
import os

# Configuration
HOST = "0.0.0.0"  # Listen on all interfaces
PORT = 7860        # Port to run the server on
PATH = "./webauth" # Directory to share via WebDAV

# Create the webauth directory if it doesn't exist
if not os.path.exists(PATH):
    os.makedirs(PATH)
    print(f"Created directory: {PATH}")

# Create a sample test.txt file inside the webauth directory
sample_file_path = os.path.join(PATH, "test.txt")
with open(sample_file_path, "w") as f:
    f.write("This is a sample file for testing the WebDAV server.\n")
print(f"Created sample file: {sample_file_path}")

# Create a FilesystemProvider to serve files from the webauth directory
provider = FilesystemProvider(PATH)

# Configure the WebDAV app
config = {
    "provider_mapping": {
        "/": provider,  # Map the root URL to the provider
    },
    "verbose": 1,  # Enable verbose logging
}

# Create the WebDAV app
app = WsgiDAVApp(config)

# Create the WSGI server
server = WSGIServer((HOST, PORT), app)

# Start the server
print(f"WebDAV server running on http://{HOST}:{PORT}")
server.start()