情况是这样,文件在A服务器目录Folder下,用户名User密码Password,已经有Administrator设好,A服务器环境为win2000 server
现在要从Application服务器B使用用户名密码连接上A服务器的目录Folder,然后下载文件txt,B服务器环境也为win2000 server。使用的语言是C#.net,求高手给解决方案,如有代码小弟感激不尽!!!
现在要从Application服务器B使用用户名密码连接上A服务器的目录Folder,然后下载文件txt,B服务器环境也为win2000 server。使用的语言是C#.net,求高手给解决方案,如有代码小弟感激不尽!!!
解决方案 »
- 怎样配置Visual Studio 2005 的默认语言?
- 关于窗体的问题,请大哥们帮帮忙,急急急急急!!!
- 关于单点登陆的问题,虚心向大家请教(c#)。。
- 投票的列项单选框和多选框怎么在代码打出来
- 在WinForm与MFC按钮不同了,??????
- 100分问个简单的问题,有关DaaColumn.Expression
- 有关用c#重写listView控件的问题
- 学C#是否有助于理解windows的运行机制?
- 这颗星星你要不要?
- 我不小心重置了工具箱的windows窗体选项卡,我的用户控件不见了,怎么找回来(不要直接浏览找dll)?
- 时间交叉的问题
- winform的treeview在xp下显示的Bug?
http://blog.csdn.net/knight94/archive/2006/03/21/631309.aspx
http://blog.csdn.net/knight94/archive/2006/03/31/645367.aspx
public static void OpenDirectory(string str_Directory,string to_Directory, string str_UserName, string str_Password)
{
string str_LogoOn = "net use " + str_Directory + " /user:" + str_UserName + " \"" + str_Password + "\"";
string str_OpenDirectory = "start " + str_Directory; Process p_Tmp = new Process();
p_Tmp.StartInfo.RedirectStandardError = true;
p_Tmp.StartInfo.RedirectStandardInput = true;
p_Tmp.StartInfo.RedirectStandardOutput = true;
p_Tmp.StartInfo.UseShellExecute = false;
p_Tmp.StartInfo.CreateNoWindow = true;
p_Tmp.StartInfo.FileName = "cmd.exe";
p_Tmp.Start();
p_Tmp.StandardInput.WriteLine(str_LogoOn);
p_Tmp.StandardInput.WriteLine(str_OpenDirectory);
p_Tmp.StandardInput.WriteLine("exit");
p_Tmp.Close();
p_Tmp.Dispose(); string[] files = Directory.GetFiles(fromDirectory);
if (files.Length > 0)
{
foreach (string s in files)
{
FileInfo objFI = new System.IO.FileInfo(s);
File.Copy(str_Directory + "\\" + objFI.Name.ToString(), to_Directory + "\\" + objFI.Name.ToString());
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;namespace IISWatcher
{ [StructLayout(LayoutKind.Sequential)]
public class NetMappingDrive
{
private int dwScope;
private int dwType;
private int dwDisplayType;
private int dwUsage;
private string strLocalName;
private string strRemoteName;
private string strComment;
private string strProvider;
private string strUsername;
private string strPassword; public string LocalDrive
{
get { return strLocalName; }
} public string NetPath
{
get { return strRemoteName; }
} public string UserName
{
get { return strUsername; }
}
public string Password
{
get { return strPassword; }
} //如果正确,返回值是0;否则错误。
[DllImport("mpr.dll", EntryPoint = "WNetAddConnection2")]
private static extern uint WNetAddConnection2([In] NetMappingDrive lpNetResource, string lpPassword, string lpUsername, uint dwFlags); [DllImport("Mpr.dll")]
private static extern uint WNetCancelConnection2(string lpName, uint dwFlags, bool fForce); public NetMappingDrive(string LocalDrive, string NetPath,string Username,string Password)
{
this.dwScope = 2;
this.dwType = 1;
this.dwDisplayType = 3;
this.dwUsage = 1;
this.strLocalName = LocalDrive;
this.strRemoteName = NetPath;
this.strProvider = null;
this.strUsername = Username;
this.strPassword = Password; } public uint CreateDrive()
{
return WNetAddConnection2(this, this.strPassword, this.strUsername, 0);
} public uint DeleteDrive()
{
return WNetCancelConnection2(this.strLocalName, 1, true);
}
}}影射为网络驱动器然后用fileinfo copy