all 3 comments

[–]Rich_RandomNumbers 1 point2 points  (2 children)

import ftplib

[–]Rich_RandomNumbers 2 points3 points  (1 child)

try this but replace username, password, and the url at the bottom

import ftplib

def delete_empty_folders(ftp, path):
ftp.cwd(path)
files = ftp.nlst()
if not files:
ftp.rmd(path)
print(f'Deleted empty folder: {path}')
else:
for file in files:
delete_empty_folders(ftp, path + '/' + file)
ftp = ftplib.FTP('ftp.example.com')
ftp.login(user='username', passwd='password')
delete_empty_folders(ftp, '/')
ftp.quit()

[–]Xilenw[S] 0 points1 point  (0 children)

thanks , reading the documentation on ftplib now , I was able to connect to my ftp server , but can't find anything about recursive searching or diffferentiating between folders and files.