我编写了一个C#控制台应用程序,它会每天按计划将备份从一台服务器复制到另一台服务器。如果我已登录到共享文件夹并且我的凭据被加密,这可以很好地工作,但是如果我的凭据没有在源服务器的共享上输入,我的代码中出现错误。我需要做的是让我的应用程序模拟登录到源的共享文件夹,这样我就可以抓取文件并将其移动到目的地。
public static void CopyNewestBackup()
{
string sourcePath = @"\\source";
string targetPath = @"\\destination";
FileInfo newestFile = GetNewestFile();
string sourceFile = Path.Combine(sourcePath, newestFile.Name);
string destFile = Path.Combine(targetPath, newestFile.Name);
Console.Write("Copying " + newestFile.Name + " from " + sourcePath + " to " + destFile);
FileSystem.CopyFile(sourceFile, destFile, UIOption.AllDialogs);
//File.Copy(sourceFile, destFile, true);
}
如何模拟登录服务器以获取文件?