6.py 617 B

1234567891011121314151617181920212223242526
  1. '''
  2. Created on 2019年10月24日
  3. @author: User
  4. '''
  5. import pyhdfs
  6. import os
  7. import codecs
  8. fs = pyhdfs.HdfsClient(hosts="192.168.48.178,50070",user_name='root1')
  9. print(fs.get_home_directory())
  10. print(fs.get_active_namenode())
  11. file = fs.get_home_directory()+"/ContentExtract.rar"
  12. localfile = os.path.abspath("./ContentExtract.rar")
  13. print(localfile)
  14. print(fs.exists(file))
  15. if not os.path.exists(localfile):
  16. with codecs.open(localfile,"w") as f:
  17. f.flush()
  18. #fs.copy_to_local(file,localfile)
  19. fs.delete(file)
  20. fs.copy_from_local(localfile,file)
  21. print(fs.listdir(fs.get_home_directory()))
  22. print(fs.exists(file))