User:Pedro Sá Couto/Prototyping 5th/LibGen FTP uploader

From XPUB & Lens-Based wiki
< User:Pedro Sá Couto‎ | Prototyping 5th
Revision as of 17:58, 19 January 2020 by Pedro Sá Couto (talk | contribs) (Created page with " <source lang="python"> import ftplib from ftplib import FTP import os import fileinput # connect to host, default port ftp = FTP('ftp.libgen.lc') # user anonymous, passwd a...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


import ftplib
from ftplib import FTP
import os
import fileinput

# connect to host, default port
ftp = FTP('ftp.libgen.lc')
# user anonymous, passwd anonymous@
ftp.login()

#change to the directory upload
ftp.cwd('upload')

#list all the directory
ftp.retrlines('LIST')

#change to the directory upload of books
ftp.cwd('/upload/_books/')

#check what is the directory we are in
ftp.pwd()

#ask in terminal for the file that is going to be uploaded
localfile = (input("What file do you want to upload? (include extention as example.pdf): "))

#use the file from  the input, read binary
fp = open(localfile, 'rb')
#1024 is the block size
ftp.storbinary('STOR %s' % os.path.basename(localfile), fp, 1024)

# close file and FTP session
fp.close()
ftp.quit()