Uploading a file using ftplib

In this post, you'll see how we can use ftplib to upload files to a ftp server. In the following example,

'import ftplib'

imports the ftp module.session = ftplib.FTP('example.com','username','password') 

makes a ftp connection to the ftp server with the specified ftp server with the supplied username/password.

file=open('cup.mp4','rb')

opens the cup.mp4 file. And then
session.storbinary('STOR cup.mp4',file)

uploads the file to ftp server.Finally we close the file with

file.close()

and then close the session

session.quit()

#!/usr/bin/python
import ftplib
session = ftplib.FTP('example.com','username','password')
file = open('cup.mp4','rb') # file to send
session.storbinary('STOR '+'cup.mp4', file) # send the file
file.close() # close file and FTP
session.quit()
view raw ftp_uploader.py hosted with ❤ by GitHub

Comments

Popular posts from this blog

Automate file upload in Selenium IDE

How To Install and Configure Nextcloud

Google translate adds Nepali Language Conversion