photo lineviral_1.png

Mass Delete Files Inwards Ftp Server

Ran into a piffling employment today, something I don’t actually produce ofttimes in addition to something many would never do! Yeah, I’m talking most FTP .. the former pre-historic service of a matter that was originally RFC’d dorsum inwards 1971. I had to mass delete files inwards FTP server, empty a folder in addition to delete that too. Sounds simple, but non really!


So this FTP server had some database in addition to the database got corrupted. Since the database got corrupted, the log directory but kept accumulating logs without deleting every bit none of the files got processed. Over time, it had most 145789 files sizes betwixt 400mb to 4gb. You know spider web logs, swells upwards when people wake upwards in addition to slows downwards when everyone off sleeping. Any how, in addition to hence right away I got to delete those 145789 files through former schoolhouse FTP. It’s supposed to endure like shooting fish in a barrel but noooo, I cannot purpose FileZilla or WinSCP or whatever GUI customer to brand my life easier. I convey to purpose CLI FTP. Let’s see:


ubuntu@ftp-client01: $ ftp
ftp> opened upwards ftp-server01
Connected to ftp-server01.
220 Welcome to the Web FTP service.
Name (ftp-server01:ubuntu): admin
331 Please specify the password.
Password:
230 Login successful.
Remote organization type is UNIX.
Using binary trend to transfer files.
ftp>
ftp> ls
200 PORT ascendance successful. Consider using PASV.
150 Here comes the directory listing.
drwxrwx--- two ftp ftp 3878912 Sep 07 00:07 Web_DC1_Log_Dir
drwxrwx--- two ftp ftp 36864 Sep 06 07:37 testdatabase
226 Directory ship OK.

So far in addition to hence good, I logged inwards in addition to tin listing the directories. It seems there’s a exam database folder every bit well. Let’s banking concern gibe the contents commencement but to ensure I am looking at the correct thing.


ftp> cd Web_DC1_Log_Dir
250 Directory successfully changed.
ftp> dir
200 PORT ascendance successful. Consider using PASV.
150 Here comes the directory listing.
-rw-r--r-- 1 ftp ftp 3778547 Jun fifteen 05:16 webserver.local01-2018-06-15-05_003.log.gz
-rw-r--r-- 1 ftp ftp 4002151 Jun fifteen 05:21 webserver.local01-2018-06-15-05_004.log.gz
-rw-r--r-- 1 ftp ftp 4139598 Jun fifteen 05:26 webserver.local01-2018-06-15-05_005.log.gz
-rw-r--r-- 1 ftp ftp 3936480 Jun fifteen 05:31 webserver.local01-2018-06-15-05_006.log.gz
-rw-r--r-- 1 ftp ftp 3772733 Jun fifteen 05:36 webserver.local01-2018-06-15-05_007.log.gz
-rw-r--r-- 1 ftp ftp 3763328 Jun fifteen 05:41 webserver.local01-2018-06-15-05_008.log.gz
-rw-r--r-- 1 ftp ftp 3725765 Jun fifteen 05:46 webserver.local01-2018-06-15-05_009.log.gz
-rw-r--r-- 1 ftp ftp 3597685 Jun fifteen 05:51 webserver.local01-2018-06-15-05_010.log.gz

226 Directory ship OK.
ftp> cd ..
250 Directory successfully changed.
ftp> cd testdatabase
250 Directory successfully changed.
ftp> dir
200 PORT ascendance successful. Consider using PASV.
150 Here comes the directory listing.
-rw-r--r-- 1 ftp ftp 1394829 April fourteen 02:00 Web_Reporter_140.log.gz.done
-rw-r--r-- 1 ftp ftp 1394711 April fifteen 02:00 Web_Reporter_150.log.gz.done
-rw-r--r-- 1 ftp ftp 1386116 April xvi 02:00 Web_Reporter_160.log.gz.done
-rw-r--r-- 1 ftp ftp 1314330 April 17 02:00 Web_Reporter_170.log.gz.done
-rw-r--r-- 1 ftp ftp 1292357 April xviii 02:00 Web_Reporter_180.log.gz.done
-rw-r--r-- 1 ftp ftp 1289469 April xix 02:00 Web_Reporter_190.log.gz.done
226 Directory ship OK.
ftp> cd ..
250 Directory successfully changed.
ftp> dir
200 PORT ascendance successful. Consider using PASV.
150 Here comes the directory listing.
drwxrwx--- two ftp ftp 3878912 Sep 07 00:12 Web_DC1_Log_Dir
drwxrwx--- two ftp ftp 36864 Sep 06 07:37 testdatabase
226 Directory ship OK.

Looks similar all adept in addition to laid upwards to go. Let’s create cli-kungfu on that earlier trying it on the master copy directory.


ftp> ?
Commands may endure abbreviated. Commands are:

! debug mdir qc send
$ dir mget sendport site
account disconnect mkdir rate size
append leave of absence mls pwd status
ascii shape trend quit struct
bell instruct modtime quote system
binary glob mput recv sunique
bye hash newer reget tenex
case assistance nmap rstatus tick
cd idle nlist rhelp trace
cdup picture ntrans rename type
chmod lcd opened upwards reset user
close ls prompt restart umask
cr macdef passive rmdir verbose
delete mdelete proxy runique ?

mdelete is definitely the agency to become every bit y'all tin delete many files. Let’s create that.


t actually produce ofttimes in addition to something many would never produce Mass delete files inwards FTP server


Now hang on, I don’t desire to confirm for each file, this is actually annoying in addition to fourth dimension consuming when y'all convey to produce it 14000 times! Let’s create something else similar rm -r or rmdir -r to produce recursive deletion.


ftp>
ftp> rm -r testdatabase
550 Remove directory performance failed.
ftp> rm -r testdatabase/*
550 Remove directory performance failed.
ftp> rmdir -r testdatabase/*
550 Remove directory performance failed.
ftp> dir
200 PORT ascendance successful. Consider using PASV.
150 Here comes the directory listing.
drwxrwx--- two ftp ftp 3878912 Sep 07 00:12 Web_DC1_Log_Dir
drwxrwx--- two ftp ftp 36864 Sep 07 00:14 testdatabase
226 Directory ship OK.
ftp> exit
221 Goodbye.

Alright, that was a fail! I searched or in addition to hence in addition to there’s in addition to hence piffling information most FTP in addition to how to delete non-empty folder or mass delete files from CLI. Everyone uses some GUI customer that allows y'all to confirm inwards bulk. Finally I constitute a way.


Apparently, y'all tin purpose usage -i flag to plow off interactive, in addition to hence FTP won’t prompt y'all for every employment when using mdelete. Hope it works:


ubuntu@ftp-client01: $ ftp -i
ftp> opened upwards ftp-server01
Connected to ftp-server01.
220 Welcome to the Reporter FTP service.
Name (ftp-server01:ubuntu): admin
331 Please specify the password.
Password:
230 Login successful.
Remote organization type is UNIX.
Using binary trend to transfer files.
ftp>
ftp>
ftp> ls
200 PORT ascendance successful. Consider using PASV.
150 Here comes the directory listing.
drwxrwx--- two ftp ftp 3878912 Sep 07 00:12 Web_DC1_Log_Dir
drwxrwx--- two ftp ftp 36864 Sep 07 00:14 testdatabase
226 Directory ship OK.
ftp> mdelete -r testdatabase/*
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.

I works! Now to create the same ascendance on the large folder:


ftp> mdelete -r Web_DC1_Log_Dir/*
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.
250 Delete performance successful.
ftp> cd Web_DC1_Log_Dir
250 Directory successfully changed.
ftp> dir
200 PORT ascendance successful. Consider using PASV.
150 Here comes the directory listing.
226 Directory ship OK.
ftp> ls
200 PORT ascendance successful. Consider using PASV.
150 Here comes the directory listing.
226 Directory ship OK.

Looks similar the directory is right away empty in addition to tin endure deleted.


ftp> cd ..
250 Directory successfully changed.
ftp> rmdir Web_DC1_Log_Dir
250 Remove directory performance successful.
ftp>
ftp> rmdir testdatabase
250 Remove directory performance successful.
ftp> dir
200 PORT ascendance successful. Consider using PASV.
150 Here comes the directory listing.
226 Directory ship OK.
ftp>
ftp> ls
200 PORT ascendance successful. Consider using PASV.
150 Here comes the directory listing.
226 Directory ship OK.
ftp> exit
221 Goodbye.

Well, that was a adept i in addition to something I don’t purpose often. Hence this post. Hope it helps the adjacent someone somehow!


Buat lebih berguna, kongsi:
close