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


Enter Your Query:
Use '%' for wildcards and quotes for "exact phrases"


Top Level » Ftp

Script to delete all remote tar.gz ftp files in a directoryLast Modified: Apr 19, 2013, 12:35 am
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;


© 2018 JBMC Software, Suite 173  3-11 Bellerose Drive, St Albert, AB  T8N 1P7  Canada.  Mon-Fri 9AM-5PM MST