to 由于要上传的文件很多,现在想把上传的东西保存在另一台网内的机子(B)上,我的作法是在B机子上新建一个共享文件夹,通过本机映射驱动来储存,但在写文件的时候提示:登陆失败,未知的用户名或错误密码 .其中我把B机子上的共享文件夹权限已设为了EVERYONE,请高手帮忙如果已经知道用户名和密码,可以映射网络驱动器,和本地硬盘一样使用。 参看 http://blog.csdn.net/knight94/archive/2006/03/21/631309.aspx http://blog.csdn.net/knight94/archive/2006/03/31/645367.aspx
可以用WebClient的UpLoadFile()方法来上传文件,很方便,代码又少.
先使用Wmi开通连接,再Copy文件 using System; using System.Management;// This example demonstrates how to connect to remote machine // using supplied credentials. class Sample_ConnectionOptions { public static int Main(string[] args) { ConnectionOptions options = new ConnectionOptions(); options.Username = UserName; //could be in domain\user format options.Password = SecurelyStoredPassword; ManagementScope scope = new ManagementScope( "\\\\servername\\root\\cimv2", options); try { scope.Connect(); ManagementObject disk = new ManagementObject( scope, new ManagementPath("Win32_logicaldisk='c:'"), null); disk.Get(); } catch (Exception e) { Console.WriteLine("Failed to connect: " + e.Message); } return 0; } }
http://www.cnblogs.com/dahuaidan410/archive/2004/10/27/57471.aspx代码不难,难的是配置两台机器的权限,必须都有一个相同帐号、密码的用户
参看
http://blog.csdn.net/knight94/archive/2006/03/21/631309.aspx
http://blog.csdn.net/knight94/archive/2006/03/31/645367.aspx
using System;
using System.Management;// This example demonstrates how to connect to remote machine
// using supplied credentials.
class Sample_ConnectionOptions
{
public static int Main(string[] args) {
ConnectionOptions options = new ConnectionOptions();
options.Username = UserName; //could be in domain\user format
options.Password = SecurelyStoredPassword;
ManagementScope scope = new ManagementScope(
"\\\\servername\\root\\cimv2",
options);
try {
scope.Connect();
ManagementObject disk = new ManagementObject(
scope,
new ManagementPath("Win32_logicaldisk='c:'"),
null);
disk.Get();
}
catch (Exception e) {
Console.WriteLine("Failed to connect: " + e.Message);
}
return 0;
}
}