Make simple ftp server more reusable and add params

This commit is contained in:
Isaac Shoebottom 2024-04-19 15:32:12 -03:00
parent 7be7397ab1
commit 93a2d7e329

View File

@ -1,16 +1,26 @@
param (
[int] [alias('p')] $port = 21,
[string] [alias('d')] $directory = '.',
[bool] [alias('w')] $write = $false
)
$venv = "\.pyftplib"
$venv = $HOME + $venv
# Create virtual environment
if (-not (Test-Path venv)) {
virtualenv venv
if (-not (Test-Path $venv)) {
write-host "Creating virtual environment at $venv"
virtualenv "$venv"
}
# Activate virtual environment
.\venv\Scripts\activate.ps1
. ($venv + "\Scripts\Activate.ps1")
# Install dependencies
pip install pyftpdlib
# Run FTP server
python -m pyftpdlib
# Not working for streaming video files
# twistd -n ftp -r .
if ($write) {
python -m pyftpdlib -p $port -d $directory -w
} else {
python -m pyftpdlib -p $port -d $directory
}