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}

# wget 下载
# ftp的文件路径可以用fileZilla先连接到frp服务器上找到具体路径,然后填到下面
wget -r -nH --no-parent --ftp-user=ftp用户名 --ftp-password=ftp密码 ftp://ftpServer的ip/文件(文件夹)路径
posted @ 2024-11-12 17:53  BrianSun  阅读(35)  评论(0)    收藏  举报