下面的腳本將刪除遠程目錄中的所有.tar.gz文件。
要影響刪除哪些文件,請更改grep值。
請注意,此腳本已經過測試,并適用于我們的情況,但您的特定設置可能需要額外的測試和調試。
#!/bin/sh
ftp_path=/remote/ftp/path
ftp_username=username
ftp_password=password
ftp_ip=remote.host.com
ftp_port=21
for i in `curl -s -l ftp://"$ftp_username":"$ftp_password"@$ftp_ip/$ftp_path/ | grep tar.gz`; do
{
echo "deleting ${ftp_path}/$i";
curl ftp://${ftp_ip}:${ftp_port}/${ftp_path}/${i} -u "${ftp_username}:${ftp_password}" -O --quote "DELE ${ftp_path}/${i}"
};
done;