Python | ftplib | FTP | при загрузке файлов на ftp сервер через python загрузка одного из файлов останавливается

Мой скрипт парсит данные и загружает их на сервер, загрузка может сработать, а может не сработать, когда зависает загрузка я перезапускаю скрипт и он может отработать нормально и загрузить все файлы, а может опять встать, вот фрагмент кода:

    ftp = FTP(ip,timeout=85)
    ftp.login(log, pas)

    def deleteAllFiles(ftp):
        for n in ftp.nlst():
            try:
                if n not in ('.', '..'):
                    print('Working on..' + n)
                    try:
                        ftp.delete(n)
                        print('Deleted...' + n)
                    except Exception:
                        print(n + ' Not deleted, we suspect its a directory, changing to ' + n)
                        ftp.cwd(n)
                        deleteAllFiles(ftp)
                        ftp.cwd('..')
                        print('Trying to remove directory ..' + n)
                        ftp.rmd(n)
                        print('Directory, ' + n + ' Removed')
            except Exception:
                print('Trying to remove directory ..' + n)
                ftp.rmd(n)
                print('Directory, ' + n + ' Removed')

    ftp.cwd(f'/domains/{DOMAINNAME}/public_html')
    deleteAllFiles(ftp)
    print('Done deleting all Files and Directories')

    files = os.listdir()

    for file in files:

        if file != '.DS_Store':

            if file.split('.')[-1] == 'html':
                with open(file, 'rb') as file_to_upload:
                    # time.sleep(0.5)
                    ftp.storbinary('STOR ' + file, file_to_upload)
                    # time.sleep(1)
                print(f'Файл {file} успешно загружен')


            if file[-3:] == 'css':
                os.chdir(file)
                ftp.mkd(file)
                cssfiles = os.listdir()
                for css in cssfiles:
                    if css != '.DS_Store':
                        with open(css, 'rb') as file_to_upload:
                            # time.sleep(0.5)
                            ftp.storbinary('STOR '+ file+'/' + css, file_to_upload)
                            # time.sleep(1)
                        print(f'Файл {css} успешно загружен')
                os.chdir('../')

            if file[-3:] == 'img':
                os.chdir(file)
                ftp.mkd(file)
                imgfiles = os.listdir()
                for img in imgfiles:
                    if img != '.DS_Store':
                        with open(img, 'rb') as file_to_upload:
                            # time.sleep(0.5)
                            ftp.storbinary('STOR '+ file+'/' +img, file_to_upload)
                            # time.sleep(1)
                        print(f'Файл {img} успешно загружен')
                os.chdir('../')

    ftp.quit()
    ftp.close()

Ответы (0 шт):