使用LFTP回显当前文件传输



我试图在传输完成后回送$file_name。但是,我找不到任何关于如何在LFTP中创建显示刚刚下载的文件名的变量的参考。

代码:

#!/bin/bash
login="myusername"
pass="notmypassword"
host="my.hosting.server"
remote_dir='/Path/To/Remote/Dir/.'
local_dir="/Path/To/Local/Dir/"
file_name=**the name of the file im downloading**
base_name="$(basename "$0")"
lock_file="/tmp/$base_name.lock"
trap "rm -f $lock_file" SIGINT SIGTERM
if [ -e "$lock_file" ]
then
    echo "$base_name is running already."
    exit
else
    touch "$lock_file"
    lftp -u $login,$pass $host << EOF
    set ftp:ssl-allow no
    set mirror:use-pget-n 5
    mirror -c -x ".r(a|[0-9])(r|[0-9])$" -P5 --log="/var/log/$base_name.log" "$remote_dir" "$local_dir"
    echo $file_name
    quit
EOF
    #osascript -e 'display notification "$file_name Downloaded" with title "Media Server"'
    rm -f "$lock_file"
    trap - SIGINT SIGTERM
    exit
fi

我认为这将是相当简单的回显当前文件,然后也添加这个变量到我的osascript触发OSX上的通知,一个文件已成功传输,但对于我的生命,我不知道如何。

我做错了什么?

干杯!

此脚本将回显示传输的每个文件,请随意清理并修改它以满足您的需要:

#!/bin/bash
echo "Script started."
download_directory="${HOME}/downloads/"
echo "Downloading to ${download_directory}"
rm ${download_directory}/*
download_log=$(mktemp)
lftp <<- EOF > ${download_log}
    # elided connection details, enter your own
    open 
    mirror -v . ${download_directory}
    quit
EOF
cat ${download_log} | awk ' { print $3 } ' | sed 's/`//' | sed 's/'''//' | xargs echo "Downloaded:"
rm -f ${download_log}
echo "Script successfully ended."

示例输出:

=> ./foobar.sh  
Script started.
Downloading to /home/downloads/
Downloaded: something1.yes testfile.txt
Script successfully ended.

使用文件验证脚本:

set xfer:verify on
set xfer:verify-command /home/user/bin/file-transferred

脚本输出(FD 1,2)被重定向,但您可以使用/dev/tty将文件名输出到终端:

#!/bin/sh
echo "$1" >/dev/tty

或者,打开另一个描述符:

lftp 3>&1 <<EOF
...
EOF

和重定向输出:

#!/bin/sh
echo "$1" >&3

相关内容

  • 没有找到相关文章

最新更新