This script of mine is storing a blank file with no .html or .py extension on my FTP server, I think it has to do with the fact that I have the file already opened in the later code, any help?

Essentially this script is going to let me edit my python and other web development works through the program while being able to upload them quickly to my FTP server.

from ftplib import FTP

def cls(): #Just a nifty function to clear the console that is pretty much cross platform compatible.
    os.system(['clear','cls'][ == 'nt'])

def ftpSet():
    global ftpConn
    global ftpUser
    global ftpPass
    global ftpPath
    ftpConn = str(input("FTP Server: "))
    ftpUser = str(input("FTP User: "))
    ftpPass = str(input("FTP Pass: "))
    if ftpPass == "":
        ftpPass = "anonymous@"
    ftpPath = str(input("FTP Path: "))
    if ftpPath == "":
        ftpPath = "/public_html/"

def ftpUpload():
    ftp = FTP("", "myuser", "mypass")
    ftp.storlines("STOR " + fileName, open(file, "rb"))

fileType = "0"

while fileType == "0":
        fileExt = str(input("Are we working on, [.html], [.py]: "))
        if ".html" in fileExt or ".htm" in fileExt:
            fileType = ".html" #Editing the file.
        elif fileExt == ".py":
            fileType = ".py" #Creating a new file.
        elif fileExt == "1":
            break #Exiting!
    except ValueError:

fileName = str(input("Name of file: "))

file = fileName + fileType

fileUsing = open(file, "a")

fileWrite = ""
print ("CMDS: [//Q = Save and Quit] [//SF = Set FTP Info] [//F = Upload File to FTP] [//N = Save and New File]")

while fileWrite != "//Q":
    fileWrite = str(input(""))
    if fileWrite != "//Q":
        fileUsing.write(fileWrite + "\n")
    if fileWrite == "//SF":
    elif fileWrite == "//F":


time.sleep(3.5) #Pause 3.5 Seconds to catch the script (temporary).

Figured it out, it was just as I thought.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.