-2

I have requirement where in i want to download the files from different machines within the local network using c#, later i will do certain processing on the downloaded files and i want to upload the files back to the respective machine from where i downloaded the files, please can i know what would be the best generic approach to achieve this.

mahesh
  • 3,067
  • 16
  • 69
  • 127

2 Answers2

2

if the files are just on there hard drive. Make the folder they are in a public drive then you can open the file using its address

Jonathan D
  • 1,364
  • 2
  • 12
  • 30
  • Thanks for the reply , yes the files are placed in the public folders on the different machines which i am trying to access – mahesh Feb 16 '12 at 10:23
  • @jonathan I write wrong comment on your last answer, so +1 on this one. – Aristos Feb 16 '12 at 10:36
2

You can use normal windows shares to accomplish this. Just share the folder and use the UNC Path to copy the file to and from. i.e.

//Copy From the share to the processing machine and swap the paths around to copy back
File.Copy(@"\\ComputerX\Share\MyFileToCopy.dat",@"c:\MyDumpFolder\MyCopiedFile.Dat");

if you need to authenticate first you can run the below method stub (taken from this so question)

private void Open_Remote_Connection(string strComputer, string strUserName, string strPassword)
{
    System.Diagnostics.ProcessStartInfo ProcessStartInfo = new System.Diagnostics.ProcessStartInfo();
    ProcessStartInfo.FileName = "net";
    ProcessStartInfo.Arguments = "use \\\\" + strComputer + "\\c$ /USER:" + strUserName + " " + strPassword;
    ProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    System.Diagnostics.Process.Start(ProcessStartInfo);
    System.Threading.Thread.Sleep(2000);
}
Community
  • 1
  • 1
TBohnen.jnr
  • 5,117
  • 1
  • 19
  • 26