0

I am trying to create a folder in remote machine which is in same network and when I ping remote machine I'm getting reply also. but when I try to create folder and try to copy files I'm getting the error

Logon failure: unknown user name or bad password."

Below is the code I m using. Is there any way I can pass user name and password to create folder and copy files into remote machine. Suggest me how this can be achieved.

string path = @"\\30.120.119.121\c$\RemoteFolder";
if (!Directory.Exists(path))
{
    Directory.CreateDirectory(path);
    string[] files = Directory.GetFiles(@"C:\Files");
    foreach (var item in files)
    {
        string file = Path.GetFileName(item);
        File.Copy(item, path+ file);
    }
}
Ken White
  • 123,280
  • 14
  • 225
  • 444
Ravikumar_n
  • 117
  • 1
  • 3
  • 11
  • What line throws that error? – Sumner Evans Dec 30 '16 at 02:26
  • 2
    Are you able to do file operation in explorer when you connect to said computer? – n0rd Dec 30 '16 at 02:26
  • If you are able to access a computer's file share like that, given that is an internet ip (not a local network), then the computer at `30.120.119.121` has some serious security issues that need to be addressed. Just because a machine responds to ICMP does not mean that it is readily exploitable for other operations. To answer your question, you can try this [Access Network Share with Credentials](http://stackoverflow.com/a/22378883/3504007) – Kraang Prime Dec 30 '16 at 02:28
  • If trying to brute force the machine, this would be why you don't allow file-shares over the internet :) – Kraang Prime Dec 30 '16 at 02:32
  • @SumnerEvans, Getting error @ Directory.CreateDirectory(path); – Ravikumar_n Dec 30 '16 at 02:41
  • @n0rd, When i try to open the \\30.120.119.121\c$\ first time it will ask for username and password. after that i m able to copy files and create folder. – Ravikumar_n Dec 30 '16 at 02:42
  • @Ravikumar_n, then you should search for how to access password protected network share, it has been answered numerous times on this site alone. Try the answers then ask for clarifications if it does not help. – n0rd Jan 05 '17 at 21:35

0 Answers0