I am trying to move files for every directory to my ftp server. But my directoryname isnt the same in my if statement for some reason
Outside the if statement I get the right result. Inside it I don't.
import os
import inspect
import ftplib
import pathlib
from datetime import datetime
from os.path import normpath, basename
from glob import glob
def main():
ftp = ftplib.FTP('localhost', 'davit', 'Davit1230')
mappen = (glob("c:\websites\*"))
print((basename(normpath(mappen[1]))))
for i in range(len(mappen)):
dirname = (basename(normpath(mappen[i])))
print(dirname)
if dirname in ftp.nlst():
print("")
else:
ftp.mkd(dirname)
ftp.mkd(dirname+"/active")
ftp.mkd(dirname+"/archive")
ftp.cwd(dirname)
if "active/styling" in ftp.nlst("active"):
pass
else:
ftp.mkd("active/styling")
if "active/index.html" in ftp.nlst("active"):
print("Website geupdate!")
ftp.rename("active/index.html", "archive/"+ datetime.now().strftime("%d-%m-%Y-%H-%M-%S")+".html")
bestandftplocatie= "active/index.html"
bestandlokaal = open("C:/websites/" + dirname+"/index.html","rb")
ftp.storlines("STOR " + bestandftplocatie, bestandlokaal)
else:
bestandftplocatie= "active/index.html"
bestandlokaal = open("C:/websites/" + dirname+"/index.html","rb")
ftp.storlines("STOR " + bestandftplocatie, bestandlokaal)
if "active/styling/style.css" in ftp.nlst("active/styling"):
pass
else:
bestandftplocatie= "active/styling/style.css"
bestandlokaal = open("C:/websites/" + dirname+"/styling/style.css","rb")
ftp.storlines("STOR " + bestandftplocatie, bestandlokaal)
ftp.cwd("/")
main()
As you can see print((basename(normpath(mappen[1])))) outside the if statement give me scherm 1, what I want. But print((basename(normpath(mappen[1])))) inside the if statement gives me the script name,run2.py.
Aucun commentaire:
Enregistrer un commentaire