0

I need to have my program transfer image files from my computer, using a winform, to a central server. However, I have never done such a thing before. I've been told the easiest way is to send my image through TCP.

Could someone please point me in the right direction of how to do this?

Sean
  • 897
  • 4
  • 20
  • 42

2 Answers2

1

You have multiple options, some of which are mentioned in your comments. Which option is right for you largely depends on other concerns (security of the files, security of the transfer, etc.)

You can transfer by IP/machine name

File.Copy(@"\\192.0.0.10\YourFolder\YourFile.jpg", Path.combine(TemporaryLocalFolder,"YourFile.jpg"), true);

Or transfer by IP/machine using impersonation for an authorized user of that shared folder:

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

WindowsIdentity identity = new WindowsIdentity(username, password);

WindowsImpersonationContext context = identity.Impersonate();

File.Copy(@"\\192.0.0.10\YourFolder\YourFile.jpg", Path.combine(TemporaryLocalFolder, "YourFile.jpg"), true);

context.Undo();

Set up FTP and use that: http://msdn.microsoft.com/en-us/library/ms229715.aspx

Or the most complicated, but still an option, use a WCF service and send it that way: http://stefanoricciardi.com/2009/08/28/file-transfer-with-wcp/

wilso132
  • 829
  • 5
  • 10
0

I think the best place to start if you want to use TCP in C# is here

As for sending the image, you can open it and read the bytes which you can directly send over the TCP connection shown in the link above. Here is the documentation regarding file methods.

This should be enough to get you started.

Aelphaeis
  • 2,593
  • 3
  • 24
  • 42