Advertisement
Guest User

Untitled

a guest
Aug 28th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import ftplib
  3. import getpass
  4.  
  5. def getFTP():
  6.  
  7. # username = getpass.getuser() --> This doesn’t prompt the user for their username. Instead, it uses the current user’s login name,
  8. # according to the user’s shell environment
  9. site_address = input('Please Enter the FTP address: ')
  10. username = input('Please Enter your username: ')
  11. password = getpass.getpass('Please Enter your password to login: ')
  12.  
  13. with ftplib.FTP(site_address) as ftp:
  14. ftp.login(username, password)
  15. ftp.cwd('/home/karn/')
  16. print(ftp.getwelcome())
  17. print ("-----------------------------------------------")
  18. print('Your Current Directory Is:', ftp.pwd())
  19. print('Listing the content of the Current Dir please wait...... ')
  20. print ("-----------------------------------------------")
  21. #ftp.dir()
  22. ftp.retrlines('LIST') # list directory contents
  23. print ("------------------------------------------------------------")
  24. download = input('Please Enetr the File name you want to Download: ')
  25. print ("------------------------------------------------------------")
  26. ftp.retrbinary('RETR ' + download, open(download, 'wb').write)
  27. print('File Download is Successful.')
  28. ftp.quit()
  29. print('Goodbye!')
  30.  
  31. getFTP()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement