upload.py 575 B

12345678910111213141516171819
  1. import os
  2. import ftplib
  3. ## aboudzein
  4. def list_files(dir):
  5. #open ftp session
  6. session = ftplib.FTP('ftp_host','username','password')
  7. for root, dirs, files in os.walk(dir):
  8. # iterate throw folder tree
  9. for name in files:
  10. file = open(os.path.join(root, name),'rb') #open the file path
  11. session.storbinary('STOR FILE' + name, file) #upload the files
  12. print(file) # print the file name
  13. file.close() # close file connection
  14. session.quit()
  15. #invoke function using folders path
  16. list_files('./folders')