gpt4 book ai didi

linux - 使用 LFTP 回显当前文件传输

转载 作者:太空宇宙 更新时间:2023-11-04 10:29:48 25 4
gpt4 key购买 nike

传输完成后,我正在尝试回显 $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.

关于linux - 使用 LFTP 回显当前文件传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40487317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com