Downloading a directory tree with ftplib

前端 未结 6 1662
名媛妹妹
名媛妹妹 2020-11-27 06:25

This will not download the contents of sub-directories; how can I do so?

import ftplib
import configparser
import os

directories = []

def add_directory(lin         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 06:46

    Using ftputil, a fast solution could be:

    def download(folder):
        for item in ftp.walk(folder):
            print("Creating dir " + item[0])
            os.mkdir(item[0])
            for subdir in item[1]:
                print("Subdirs " +  subdir)
            for file in item[2]:
                print(r"Copying File {0} \ {1}".format(item[0], file))
                ftp.download(ftp.path.join(item[0],file), os.path.join(item[0],file))
    

提交回复
热议问题