0

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'][os.name == '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("ftp.myurl.com", "myuser", "mypass")
    ftp.cwd("/public_html/")
    ftp.storlines("STOR " + fileName, open(file, "rb"))
    time.sleep(5.5)
    ftp.quit

fileType = "0"

while fileType == "0":
    try:
        cls()
        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!
        else:
            continue
    except ValueError:
        continue

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

file = fileName + fileType
cls()

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":
        ftpSet()
    elif fileWrite == "//F":
        ftpUpload()


fileUsing.close()

time.sleep(3.5) #Pause 3.5 Seconds to catch the script (temporary).
1
Contributor
1
Reply
13
Views
3 Years
Discussion Span
Last Post by Anthony_7
0

Figured it out, it was just as I thought.

Edited by pyTony: Bad formatting removed.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.