lib install:
pip install pyhdfs
Python Code:
# -*- coding:utf-8 -*-
__author__ = 'yangxin_ryan'
import pyhdfs
class FileManager(object):
# upload file to hdfs from local file system
def file_upload(self, host, user_name, local_path, hdfs_path):
print("file upload start")
fs = pyhdfs.HdfsClient(hosts=host, user_name=user_name)
print(fs.listdir('/'))
fs.copy_from_local(local_path, hdfs_path)
print("file upload finish")
# download file from hdfs file system
def file_down(self, host, user_name, local_path, hdfs_path):
print("file download start")
fs = pyhdfs.HdfsClient(hosts=host, user_name=user_name)
fs.copy_to_local(hdfs_path, local_path)
print("file download finish")
if __name__ ==