上传文件使用WebClient类文件服务器 [英] Uploading files to file server using webclient class

查看:350
本文介绍了上传文件使用WebClient类文件服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我已经从我的web应用程序接收上传文件的应用程序。我现在需要该文件传送到恰好位于相同网络上的文件服务器(然而,这可能不总是这种情况)。

Currently I have an application that receives an uploaded file from my web application. I now need to transfer that file to a file server which happens to be located on the same network (however this might not always be the case).

我正在试图使用C#.NET WebClient类。

I was attempting to use the webclient class in C# .NET.

    string filePath = "C:\\test\\564.flv";
    try
    {
        WebClient client = new WebClient();

        NetworkCredential nc = new NetworkCredential(uName, password);

        Uri addy = new Uri("\\\\192.168.1.28\\Files\\test.flv");
        client.Credentials = nc;
        byte[] arrReturn = client.UploadFile(addy, filePath);
        Console.WriteLine(arrReturn.ToString());
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }

位于192.168.1.28本机是一种文件服务器,并具有一共享C:\\文件。
截至目前,我收到登录错误而失败错误的用户名或密码,但我可以在这条道路登录成功打开资源管理器和类型。我也可以登录使用远程桌面,所以我知道该用户帐户的作品。

The machine located at 192.168.1.28 is a file server and has a share c:\Files. As of right now I am receiving an error of Login failed bad user name or password, but I can open explorer and type in that path login successfully. I can also login using remote desktop, so I know the user account works.

此错误的任何想法?
是否有可能直接传输文件这样呢?随着WebClient类或者一些其他类的?

Any ideas on this error? Is it possible to transfer a file directly like that? With the webclient class or maybe some other class?

推荐答案

只需使用

File.Copy(filepath, "\\\\192.168.1.28\\Files");

一个窗口文件共享通过UNC路径曝光将被视为文件系统的一部分,并没有任何与网络。

A windows fileshare exposed via a UNC path is treated as part of the file system, and has nothing to do with the web.

用于将ASP.NET辅助进程或已启用任何模拟的凭据。如果你能调整那些得到它的权利,这是可以做到。

The credentials used will be that of the ASP.NET worker process, or any impersonation you've enabled. If you can tweak those to get it right, this can be done.

您可能会因为你正在使用的IP地址而不是服务器名称遇到问题(窗口信任设置prevent离开域 - 通过使用IP你是隐藏任何域详细信息)。 如果可能的话,使用服务器名!

You may run into problems because you are using the IP address instead of the server name (windows trust settings prevent leaving the domain - by using IP you are hiding any domain details). If at all possible, use the server name!

如果这不是在同一个Windows域,并且您尝试使用不同的域帐户,您将需要指定的用户名是[domain_or_machine] \\ [用户​​名]

If this is not on the same windows domain, and you are trying to use a different domain account, you will need to specify the username as "[domain_or_machine]\[username]"

如果您需要指定明确凭据,你需要寻找到编码一个模拟解决方案

If you need to specify explicit credentials, you'll need to look into coding an impersonation solution.

这篇关于上传文件使用WebClient类文件服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆