Skip to content

Instantly share code, notes, and snippets.

@Lizdo
Created February 17, 2010 16:37
Show Gist options
  • Save Lizdo/306784 to your computer and use it in GitHub Desktop.
Save Lizdo/306784 to your computer and use it in GitHub Desktop.
from ftplib import FTP
### Clean up all the mac resource fork files starting with ._ on FTP
def main():
f = FTP('121.199.122.95')
f.login('zsj2q1','e2d7t6c3')
print ('logging in')
clearDir(f,'htdocs')
f.close()
def clearDir(f, remotedir):
print 'current dir: ', remotedir
try:
f.cwd(remotedir)
except ftplib.error_perm, msg:
print "Can't chdir to", repr(remotedir), ":", repr(msg)
else:
subdirs = []
listing = []
filesfound = []
f.retrlines('LIST -la', listing.append)
for line in listing:
words = line.split(None, 8)
filename = words[-1].lstrip()
mode = words[0]
print filename
if filename == '.' or filename == '..':
continue
if mode[0] == 'd':
subdirs.append(filename)
continue
elif filename[0:2] == '._':
print 'Delete ', remotedir, filename
f.delete(filename)
for subdir in subdirs:
clearDir(f, subdir)
f.cwd('..')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment