Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import ftplib
- import getpass
- def getFTP():
- # username = getpass.getuser() --> This doesn’t prompt the user for their username. Instead, it uses the current user’s login name,
- # according to the user’s shell environment
- site_address = input('Please Enter the FTP address: ')
- username = input('Please Enter your username: ')
- password = getpass.getpass('Please Enter your password to login: ')
- with ftplib.FTP(site_address) as ftp:
- ftp.login(username, password)
- ftp.cwd('/home/karn/')
- print(ftp.getwelcome())
- print ("-----------------------------------------------")
- print('Your Current Directory Is:', ftp.pwd())
- print('Listing the content of the Current Dir please wait...... ')
- print ("-----------------------------------------------")
- #ftp.dir()
- ftp.retrlines('LIST') # list directory contents
- print ("------------------------------------------------------------")
- download = input('Please Enetr the File name you want to Download: ')
- print ("------------------------------------------------------------")
- ftp.retrbinary('RETR ' + download, open(download, 'wb').write)
- print('File Download is Successful.')
- ftp.quit()
- print('Goodbye!')
- getFTP()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement