Credit: Neil Cowburn
int port = 99; // Port to connect to
string filePath = @"\path\to\my\file.ext"; // The File to send
IPAddress ip = IPAddress.Parse("127.0.0.1");
IPEndPoint ipep = new IPEndPoint(ip, port); // IPEndPoint used
Socket.Connect
// Read in the file to a byte array
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] buffer = new byte[2048]; // Set the buffer length to 2KB
fs.Read(buffer, 0, (int)fs.Length);
// Set up the socket and connect
Socket sck = new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
sck.Connect(ipep);
// Send the byte array to the server
sck.Send(buffer,SocketFlags.None);