def _get_files_in_dir(ftp_session, source, dest, status):
filelist = ftp_session.nlst()
for path in filelist:
local_path = os.path.join(dest, path)
remote_path = source + path
try:
# See if it's a directory
new_remote_path = source + path + "/"
ftp_session.cwd(source + path + "/")
# It is! So we should create the directory on dest
try:
os.mkdir(local_path)
except OSError:
logger.debug("Dir: {0} already exists".format(local_path))
logger.debug("Get Folder: {0}".format(new_remote_path))
_get_files_in_dir(ftp_session, new_remote_path, local_path, status)
except ftplib.error_perm:
logger.debug("Get file: {0}".format(path))
with open(local_path, "wb") as file_handle:
ftp_session.retrbinary(
"RETR " + remote_path, file_handle.write)
评论列表
文章目录