开发者

file transfer using NetworkCredential

While transferring the file from one machine to another machine using C#.Net without socket code is as follows:

string filePath = "C:\\tags.txt";
try
{
    WebClient client = new WebClient();
    string uName = "myU开发者_开发技巧serName", password ="myPassword";
    NetworkCredential nc = new NetworkCredential(uName, password); 
    Uri addy = new Uri("\\192.168.1.28\\Files\\ tags.txt");
    client.Credentials = nc;
    byte[] arrReturn = client.UploadFile(addy, filePath);
    Console.WriteLine(arrReturn.ToString());
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
} 

"192.168.1.28\Files\ tags.txt"-> this is another machine IP and location when I debug the error occured in the Uri Class.

Error is-> Invalid URI: The format of the URI could not be determined.

Here I could send the file to target machine if the location is in share.

Ii need to send a file to the corresponding location even if the folder is not shared.

Is the above code correct code?


have you tried something like File.Copy()? I'm not sure if File.Copy uses Windows credentials. if it does then this is the easiest way to transfer files between two computers.

client.UploadFile() can also use two string parameters instead of an URI and a string; you could try sending the URI via a string.

where you wrote the Uri you need to put 4 slashes in front of the ip

//This is unrelated
//System.Text.Encoding.ASCII.GetString(arrReturn)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜