各位大哥大姐,菜鸟 现求助问题:如下是一段从服务器如\\111.111.111.xx下载一个文件,但是现在发现,下载登录服务器失败,提示信息:“未知的用户名与密码“。手动登录到\\111.111.111.11下载则是没有问题,所以应该是我登录到服务器的有问题,请教各位大侠,如何根据用户名和密码登录到这个\\111.111.111.11服务器上。很急,谢谢帮忙。
//Download file
public static bool DownloadFile(string urlString,string fileName,string fielPath)
{
//<summary>
//下载服务器文件至客户端
//</summary>
//<param name="URL">被下载的文件地址,绝对路径</param>
//<param name="fielPath">绝对路径</param>
string URL = null;
if (urlString.EndsWith(@"\") == false)
{
URL = urlString + @"\";
}
URL = URL + fileName;
WebRequest myre = WebRequest.Create(URL);
WebClient myWebClient = new WebClient();
myWebClient.UseDefaultCredentials = true;
myWebClient.Credentials = new NetworkCredential("Admini", "1111");
//string fileName = URL.Substring(URL.LastIndexOf("\\") + 1); //被下载的文件名
try
{
myWebClient.DownloadFile(URL, fielPath);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
return true;
//Download file
public static bool DownloadFile(string urlString,string fileName,string fielPath)
{
//<summary>
//下载服务器文件至客户端
//</summary>
//<param name="URL">被下载的文件地址,绝对路径</param>
//<param name="fielPath">绝对路径</param>
string URL = null;
if (urlString.EndsWith(@"\") == false)
{
URL = urlString + @"\";
}
URL = URL + fileName;
WebRequest myre = WebRequest.Create(URL);
WebClient myWebClient = new WebClient();
myWebClient.UseDefaultCredentials = true;
myWebClient.Credentials = new NetworkCredential("Admini", "1111");
//string fileName = URL.Substring(URL.LastIndexOf("\\") + 1); //被下载的文件名
try
{
myWebClient.DownloadFile(URL, fielPath);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
return true;