上传文件到FTP服务器

上传文件到FTP服务器

前言

通常情况下:我们可以使用curl来上传文件到ftp服务器,但是却不能同时上传多个文件。因此:我这里写了一个脚本,可以同时上传多个文件到指定的ftp服务器。

如何使用

  • 使用bash upload_file_to_ftp.sh <filename1> <filename2>
  • 连接不同ftp服务器只需要修改curl -T $file ftp://59.11.43.26:60021/XWP01/ -u public:Public@163 --ftp-pasv
  • 使用帮助bash upload_file_to_ftp.sh -h

代码如下:

#!/bin/bash

###
### author: 1391578633@qq.com
### This script will upload file to an ftp server
### You can use "sh upload_file_to_ftp.sh [filename] <filename>..."
### Yes! You can upload multiple files at once!
###

let arg_num=$#
declare -A args
help_info=$1
args=$@
function check1() {
        if [ $arg_num -lt 1 ];then
                                echo -e "\033[1;31m""No enough argument""\033[0m"
                echo "Usage: bash $0 filename||dirname ..."
                exit 1
                elif [ $arg_num -eq 1 ] && [ "-h" == $help_info ];then
                                help
                                exit 1
        fi
}

function check2() {
                for filename in $args;do
                                if [ ! -f $filename ];then
                                                echo -e "\033[1;31m""$filename is not exist or not a file""\033[0m"
                                                exit 1
                                else
                                                file_size=`du -sh $filename | awk '{print $1}'`
                                                echo -e "\033[1;34m""$filename: $file_size""\033[0m"
                                fi
                done
}

function help() {
                awk -F '### ' '/^### / {print $2}' "$0"
}

function main() {
                check1
                check2
                for file in $args;do
                                curl -T $file ftp://59.11.43.26:60021/XWP01/ -u public:Public@163 --ftp-pasv
                done
}
main
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值