webdav / app.py
sigyllly's picture
Upload 2 files
a051613 verified
raw
history blame
1.26 kB
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()