My project is FTP, and I need some help.
1. I'm using Huffman Code to compress file and then send it to the computer that is asking the file.
The function from the huffman code returns byte array.
I don't understand how to send the bytes.
I have this function:
private void UpLoad(string namefile)
{
try
{
FileInfo ftemp = new FileInfo(ClientForm.SharedFolderPath + "\\" + namefile); // file name
long total = ftemp.Length; // size of file in long
long rdby = 0;
int len = 0; // the numbers of bytes to read
byte[] buffed = new byte[1024];
//Open the file requested for download
FileStream fin = new FileStream(ClientForm.SharedFolderPath + "\\" + namefile, FileMode.Open, FileAccess.Read);
//One way of transfer over sockets is Using a NetworkStream
//It provides some useful ways to transfer data
NetworkStream nfs = client.GetStream();
//lock the Thread here
lock (this)
{
while (rdby < total && nfs.CanWrite)
{
//Read from the File (len contains the number of bytes read)
len = fin.Read(buffed, 0, buffed.Length);
//wait for downloader..
Thread.Sleep(1);
//Write the Bytes on the Socket
nfs.Write(buffed, 0, len);
//Increase the bytes Read counter
rdby = rdby + len;
}
//Display a Message Showing Sucessful File Transfer
fin.Close();
}
}
catch (Exception ed)
{
MessageBox.Show(ed.Message);
}
}
Can someone help me please?
- I need to identify when the file is compressed and if its not, I need to compress it.
What is the best way to do that?