mountftp.sh

写了一个shell脚本,用于mount FTP的fs,前提是已经安装curlfptfs。挂载后可以读写

#!/bin/bash

function pretreatment(){
    if which curlftpfs; then
        echo "Found." 
    else
        echo -e "The command \"curlftpfs\" does not exist, please install it before running this script."
        exit
    fi

    uid_test
    echo "Got your UID: $uid"


}

function uid_test(){
    case $(uname -s) in 
        Linux)
            uid=$(cat /etc/passwd | grep $(whoami) | awk -F: '{print $3;}');;
        Darwin)
            uid=$(dscl . -list /Users UniqueID | grep  $(whoami)   | awk '{print $2}');;
        *)
            echo "Unknown system (not Linux or macOS). Continue or not? (y or n)"
            read choice1;
            if [ "$choice1" == "y" ]; then
                read -p "Please input your UID" uid
            else
                exit
            fi
            ;;
    esac
}

function connect(){
    read -p "Server address (without prefix ftp://): " address

    read -p "Login name: " username

    read -s -p "Login password: " password
    echo

    read -p "Local directory: " directory

    echo "Now will mount the FTP to the local file system."
    echo 

    read -p "Press enter to continue."
    echo
    echo -e "Running \"curlftpfs -o rw,allow_other,uid=${uid} ftp://${username}:****@${address} $directory\". "

    curlftpfs -o rw,allow_other,uid=${uid} ftp://${username}:${password}@${address} ${directory}
}



function retry_test(){
if [ "$?" -ne 0 ]; then
    echo
    echo "Failed. Would you like to retry? ( y or n )"
    read choice2
    if [ "$choice2" == "y" ]; then
        connect
        retry_test    
    else 
        exit
    fi
else
    echo "Successfully mounted."
    echo
fi
}

pretreatment
connect
retry_test

 

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注