python-如何解决找不到路径错误的问题

时间:2019-05-23 15:04:49

标签: python path ftp xampp

对于学校来说,我们必须编写一个脚本,该脚本将文件存储在当前文件夹中,并通过ftp将其放置在存档文件夹中,但始终会显示错误:[WinError 3] can't find path: '/website/monitor1/current/'

我已经尝试过更改ftp用户,其主目录并更改路径,但是没有任何作用。

from ftplib import FTP 
import os
import getpass
import time
import shutil
import time
import zipfile


username = getpass.getuser() 


os.chdir('C:\\Users\\' + username + '\\OneDrive - Miniemeninstituut\\EindProject\\website')


map_monitoren = ['monitor1','monitor2','monitor3','monitor4','monitor5','monitor6']
monitoren = ['monitor1.html','monitor2.html','monitor3.html','monitor4.html','monitor5.html','monitor6.html']


ftp = FTP('127.0.0.1')
ftp.login(user='lander', passwd='1234')

#tijd
tijd = time.strftime('%Y-%m-%d %H;%M;%S')





def return_to_archive(): 
    teller = 0
    while teller < 6:
        ftp.cwd('/')
        source = ('/website/'+ map_monitoren[teller] +'/current/')
        dest = ('/website/'+ map_monitoren[teller] +'/archive/')


        files = os.listdir(source)

        teller = teller + 1
        for f in files:
                shutil.move(source+f, dest)

return_to_archive()





def placeFile():   
    teller = 0
    while teller < 6:
        ftp.cwd('/')
        ftp.cwd('/website/'+ map_monitoren[teller] +'/current')
        filename = monitoren[teller]
        teller = teller + 1
        ftp.storbinary('STOR ' + tijd + '_' + filename, open(filename,'rb')) #file word binair opgeslagen
    ftp.quit()
placeFile()




def backup():



    backup_directory = ('C:\\Users\\' + username + '\\OneDrive - Miniemeninstituut\\EindProject\\backup')

    print('Bezig met maken van Backup')

    #filename maken
    backup_zip = zipfile.ZipFile(backup_directory + '\\' + 'backup' + '_' + tijd + '.zip', 'w')

    print('Nog even geduld')


    for folder, subfolders, files in os.walk('/website'):
        for file in files:
            backup_zip.write(os.path.join(folder, file), os.path.relpath(os.path.join(folder,file), 'C:\\xampp\\htdocs\\eindwerk\\website'), compress_type = zipfile.ZIP_DEFLATED)
    backup_zip.close()


backup()

它应该将文件放在当前文件中,但是会出现错误: [WinError 3] can't find path: '/website/monitor1/current/'

0 个答案:

没有答案