Два компьютера подключены к одной локальной сети. Я пытаюсь скопировать файл из удаленной системы в мою локальную систему, используя C #. Но я не могу скопировать файл из удаленной системы. Но я могу делать копии в самой удаленной системе.
Для выполнения WQL (запросов WMI) в удаленной системе
ObjectQuery query = new ObjectQuery("SELECT * FROM CIM_DataFile WHERE
FileName='test' AND Extension='txt'");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
queryCollection = searcher.Get();
ManagementBaseObject inParams, outParams;
string localPath = "C:\\Users\\UserName\\Desktop\\log.txt";
string remotePath = "\\\\RemoteComputer\\C:\\Folder1\\Testing\\test.txt";
foreach (ManagementObject m in queryCollection)
{
// Display the remote file information in local system
Console.WriteLine("Name :{0}", m["Name"]);
Console.WriteLine("File status :{0}", m["Status"]);
Console.WriteLine("File Type :{0}", m["FileType"]);
Console.WriteLine("Object Name :" + m.ToString());
Console.WriteLine("\nFile copying has been initiated ...");
// Method - 1
using (FileStream localDest = File.OpenWrite(localPath))
using (FileStream remoteSource = File.OpenRead(remotePath))
{
remoteSource.CopyTo(localDest);
}
// Method - 2
File.Copy(remotePath, localPath, true);
// Method - 3
inParams = m.GetMethodParameters("Copy");
inParams["FileName"] = localPath;
outParams = m.InvokeMethod("Copy", inParams, null);
Console.WriteLine("Return value :" + outParams["ReturnValue"]);
Console.WriteLine("\nFile copying completed !");
}
Но код копирует файл из удаленной системы в локальную систему. Я могу копировать в удаленной системе, но не могу скопировать это в мою локальную систему