C# WebClient上传下载资料问题求助
2013-12-31 09:55
351 查看
各位大哥大姐,菜鸟 现求助问题:如下是一段从服务器如\\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;
相关文章推荐
- C# WebClient上传下载时进度条显示
- c# HttpClient上传和下载的进度显示问题
- C# WebClient进行FTP服务上传文件和下载文件
- C# webclient中文乱码问题解决方法
- C# HttpWebRequest 上传大文件 超时问题
- C#下载报错:An exception occurred during a WebClient request.,不知道如何处理。
- java web上传、下载文件源码以及应该注意的问题
- c# WebClient.DownloadFile文件下载方法
- C#上传下载文件ftp操作类FTPClient代码
- C# HttpWebRequest可断点上传,下载文件;SOCKET多线程多管道可断点传送大文件
- C#下载报错:An exception occurred during a WebClient request.,不知道如何处理。
- WebClient 上传下载用法
- 关于用FTPClient资源库上传下载以中文命名的文件的问题
- [No0000DB]C# FtpClientHelper Ftp客户端上传下载重命名 类封装
- c# WebClient上传文件到远程服务器 分类: .NET 2012-12-23 15:16 1627人阅读 评论(0) 收藏
- FTPClient实现ftp的上传下载(包含中文文件名和中文路径问题)
- C# Webclient 文件远程上传
- SpringMVC整合fastdfs-client-java实现web文件上传下载
- c# WebClient上传文件到远程服务器
- java-web文件上传下载,可解决多个安全访问问题