Python实现HDFS文件上传、下载操作

2022-12-29 08:37:55

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__ ==
  • 作者:杨鑫newlfe
  • 原文链接:https://yangxin.blog.csdn.net/article/details/87621618
    更新时间:2022-12-29 08:37:55