403在使用hadoop.webhdfsclient时创建文件,不过能够在hdfs中创建文件夹

aor9mmx1  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(365)

此代码一直工作到文件夹创建无法创建文件并抛出403。我是不是漏掉了什么认证的东西。我是hadoop的新手,正在努力学习hdinsight。

private static void uploadFile()
    {
        //set variables
        string srcFileName = @"./prime/in/integers.txt";
        string destFolderName = @"/prime/in";
        string destFileName = @"integers.txt";
        string outputFolderName= @"/prime/out";
        //connect to hadoop cluster
        Uri myUri = new Uri("http://DXPZN72-LP:50070");
        string userName = "hadoop";
        WebHDFSClient myClient = new WebHDFSClient(myUri, userName);

        //drop destination directory (if exists)
        myClient.DeleteDirectory(destFolderName, true).Wait();

        //create destination directory
        myClient.CreateDirectory(destFolderName).Wait();

        //create outputFolderName directory
        myClient.CreateDirectory(outputFolderName).Wait();

        //load file to destination directory
        var res= myClient.CreateFile(srcFileName,  "/" +destFileName);
        res.Wait();
        //list file contents of destination directory
        Console.WriteLine();
        Console.WriteLine("Contents of " +destFolderName);

        myClient.GetDirectoryStatus(destFolderName).ContinueWith(
             ds => ds.Result.Files.ToList().ForEach(
             f => Console.WriteLine("t" +f.PathSuffix)
             ));

        //keep command window open until user presses enter
        Console.ReadLine();
    }
vnzz0bqm

vnzz0bqm1#

发现这是一个需要重新启动的服务。虽然我可以创建文件夹,但无法使用403创建文件。
我重新启动了我的机器,然后再试一次,问题消失了,我也可以创建文件。

相关问题