Я получаю сообщение об ошибке «urllib.error.URLError: "тогда как папки копируются, а файлы нет. Посоветуйте, что не так с этим кодом. Спасибо.
import sys import ftplib import urllib.request import os import time import errno from ftplib import FTP_TLS
server = "localhost" user = "user" password = "1234" source = "/" destination = "/ Users / user / Desktop / DestinationA /" interval = 0,05 порт = 21
def downloadFiles (путь, пункт назначения): попробуйте: ftp.cwd (путь) os.chdir (пункт назначения) mkdir_p (пункт назначения [0: len (пункт назначения) - 1] + путь) print ("Создатель:" + пункт назначения [0 : len (destination) - 1] + path) except OSError: pass except ftplib.error_perm: print («Ошибка: не удалось изменить на» + путь) sys.exit («Завершение приложения»)
filelist = ftp.nlst()
print(filelist)
for file in filelist:
time.sleep(interval)
if "." in file:
url = ("ftp://" + server + path + file)
urllib.request.urlretrieve(url, destination + path + file)
else:
try:
ftp.login(user, password)
ftp.cwd(path + file + "/")
downloadFiles(path + file + "/", destination)
except ftplib.error_perm:
os.chdir(destination[0:len(destination) - 1] + path)
try:
ftp.retrbinary("RETR " + file, open(os.path.join(destination + path, file), "wb").write)
print("Downloaded: " + file)
except:
print("Error: File could not be dld " + file)
return
def mkdir_p (path): try: os.makedirs (path) except OSError as ex c: if ex c .errno == errno.EEXIST и os.path.isdir (path): pass else: raise
с ftplib.FTP (сервером) как ftp: ftp.connect (сервер, порт) ftp.login (пользователь, пароль)
downloadFiles(source, destination)