debian11 使用python3 启动http文件服务器和ftp服务器脚本

http 文件服务器

start_http_server.sh

#!/bin/bash
port=$1
host=0.0.0.0

function Usage()
{
    echo -e "Usage:${0} [port]"
    exit 0
}

if [[ ${port} == "" ]];then
    Usage
fi

# 检查端口号是否被占用
check_port=`netstat -ant|grep LISTEN|grep ${port}`
if [[ ${check_port} != "" ]];then
    echo -e "Error! port:${port} is already in use"
    Usage
fi


python3 -m http.server --bind ${host} ${port}

ftp 服务器

start_ftp_server.sh

#!/bin/bash
port=$1
host=0.0.0.0

dir_path=/root/shell
user_name=ftpuser
user_pwd=ftpuser

function Usage()
{
    echo -e "Usage:${0} [port]"
    exit 0
}


if [[ ${port} == "" ]];then
    Usage
fi

# 检查端口号是否被占用
check_port=`netstat -ant|grep LISTEN|grep ${port}`
if [[ ${check_port} != "" ]];then
    echo -e "Error! port:${port} is already in use"
    Usage
fi

has_lib=`pip3 list|grep pyftpdlib|grep -v grep`
if [ -z "${has_lib}" ];then
        echo "not find pip3 lib pyftpdlib, try install it"
        pip3 install pyftplib
fi

python3 -m pyftpdlib -i ${host} -p ${port} -d ${dir_path} -D  -u ${user_name} -P ${user_pwd}
posted @ 2024-11-12 17:53  BrianSun  阅读(3)  评论(0编辑  收藏  举报