how to upload python file in python code example

Example: python script to upload file to server

## To start:

from ftplib import FTP

# Domain name or server ip:
ftp = FTP('123.server.ip')
ftp.login(user='username', passwd = 'password')

## The above will connect you to your remote server. You can then change into a specific directory with:

ftp.cwd('/whyfix/')

## Now, let's show how we might download a file:

def grabFile():

    filename = 'example.txt'

    localfile = open(filename, 'wb')
    ftp.retrbinary('RETR ' + filename, localfile.write, 1024)

    ftp.quit()
    localfile.close()
    
## Next, how about uploading a file?

def placeFile():

    filename = 'exampleFile.txt'
    ftp.storbinary('STOR '+filename, open(filename, 'rb'))
    ftp.quit()

placeFile()