Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python-FTP download all files in directory
- from ftplib import FTP
- import os, sys, os.path
- def handleDownload(block):
- file.write(block)
- print ".",
- ddir='C:\Data\test\'
- os.chdir(ddir)
- ftp = FTP('test1/server/')
- print 'Logging in.'
- ftp.login('user1\anon', 'pswrd20')
- directory = '\data\test\'
- print 'Changing to ' + directory
- ftp.cwd(directory)
- ftp.retrlines('LIST')
- print 'Accessing files'
- for subdir, dirs, files in os.walk(directory):
- for file in files:
- full_fname = os.path.join(root, fname);
- print 'Opening local file '
- ftp.retrbinary('RETR C:\Data\test\' + fname,
- handleDownload,
- open(full_fname, 'wb'));
- print 'Closing file ' + filename
- file.close();
- ftp.close()
- cd c:destination
- wget --mirror --continue --no-host-directories --user=username --password=s3cr3t ftp://hostname/source/path/
- for subdir, dirs, files in os.walk(directory):
- >>> class c:
- ... def __call__(self, *args):
- ... print(args)
- ...
- >>> f = c()
- >>> f('hello')
- ('hello',)
- >>> f('hello', 'world')
- ('hello', 'world')
- class handle_lines:
- def __init__(self):
- self.lines = []
- def __call__(self, *args):
- self.lines << args[0]
- filenames = []
- ftp.retrlines('NLST', filenames.append)
- print filenames
- for filename in filenames:
- local_filename = os.path.join('C:\test\', filename)
- file = open(local_filename, 'wb')
- ftp.retrbinary('RETR '+ filename, file.write)
- file.close()
- ftp.close()
Add Comment
Please, Sign In to add comment