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,
imports the ftp module.
makes a ftp connection to the ftp server with the specified ftp server with the supplied username/password.
opens the cup.mp4 file. And then
uploads the file to ftp server.Finally we close the file with
and then close the session
'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()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Comments
Post a Comment