将压缩文件从一台计算机移动到另一台计

时间:2014-04-14 11:47:06

标签: c# ftp

我的项目是FTP,我需要一些帮助 1.我正在使用Huffman Code压缩文件,然后将其发送到询问文件的计算机。

来自霍夫曼代码的函数返回字节数组 我不明白如何发送字节。

我有这个功能:

    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);
        }
    }
是的,有人能帮帮我吗?

  1. 我需要确定文件何时被压缩,如果不是,我需要压缩它。
  2. 最好的方法是什么?

0 个答案:

没有答案