Answers for "python script to upload file to server"

0

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()
Posted by: Guest on May-18-2021

Code answers related to "python script to upload file to server"

Python Answers by Framework

Browse Popular Code Answers by Language