0

I am trying to copy files at specific directory from my pc to remote pc (server) as shown below but I am getting an error message access to path denied

I tried to copy files to my local pc not the remote one and filed for the same reason

I also tried to run the exe as administrator form Debug foleder but I got same error message

another question for now the remote pc has no password or username so can I use same way but with password authentication ?

private void PatchUpdates()
{
    try
    {
        string[] array = Directory.GetFiles(Sfilespath, "*.txt");

        foreach (string name in array)
        {
            MessageBox.Show(Path.GetFileNameWithoutExtension(name));
            MessageBox.Show(@"D:\" + Path.GetFileNameWithoutExtension(name));
            File.Copy(Sfilespath, @"D:\" + Path.GetFileNameWithoutExtension(name), true);
        //File.Copy(SBankfilespath, "\\\\192.168.1.28\\Files");


        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}
sam
  • 2,493
  • 6
  • 38
  • 73
  • 1
    The problem might be the source of the copy command, not the destination. Try to pass the found file names instead of the path where you are looking for files: `File.Copy(name, @"D:\" + Path.GetFileNameWithoutExtension(name), true);` – Markus Gilli Dec 15 '16 at 12:03
  • @MarkusGilli Thanks Problem Solved.. Please post your comment as answer and ill mark it as solution... and any suggestion to pass username and password for the server ? – sam Dec 15 '16 at 13:13

2 Answers2

2

The problem might be the source of the copy command, not the destination. Try to pass the found file names instead of the path where you are looking for files: File.Copy(name, @"D:\" + Path.GetFileNameWithoutExtension(name), true);

You can probably just run net use \\\\192.168.1.28\\Files /user:username password using Process.Start before copy the files. Or check Accessing a Shared File (UNC) From a Remote, Non-Trusted Domain With Credentials for a proper solution.

Community
  • 1
  • 1
Markus Gilli
  • 227
  • 2
  • 8
  • thanks I'll also check your suggested way to access remote files/folders and feedback – sam Dec 16 '16 at 10:39
0

I got "access denied" while copying from one network folder to the other. I solved it by defining a specific identity for relevant the application pool, a user which has access to the path.

Oranit Dar
  • 1,539
  • 18
  • 17