python上传下载集群hdfs(转载)

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__ == '__main__':
    file_manager = FileManager()
    file_manager.file_upload("192.168.12.101:50070", "admin", u"airport_inf.xls",
                             u"/airport_fare_data/his_data/airport_inf.xls")
    # file_manager.file_down("ip:50070", "admin", u"local_file.xlsx", u"hdfs_file.xlsx")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值