Add to Favourites Add to Favourites    Print this Article Print this Article

Script to delete all remote tar.gz ftp files in a directory

The script below will delete all .tar.gz files in a remote directory.
To affect which files are removed, change the grep value.
Note that this script has been tested, and works in our case, but extra testing and debugging may be required for your specific setup.

#!/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;



Was this answer helpful?

Also Read