public void CopyClient(List <string> sources, ref object clientStream)
        {
            string source = sources[0];
            string target = sources[1];

            sources.RemoveRange(0, 2);
            object filex;
            Stream iStream;

            for (int i = 0; i < sources.Count; ++i)
            {
                // if copy the file sources[i]
                if (File.Exists(source + "\\" + sources[i]) == true)
                {
                    iStream = new FileStream(source + "\\" + sources[i], FileMode.Open);
                    filex   = new FileX(target + "\\" + sources[i], "file", (int)iStream.Length);
                    Object2Object(filex, ref clientStream);
                    Object2Object(iStream, ref clientStream);
                    ((Stream)iStream).Close();
                }
                else // copy the folder sources[i]
                {
                    // create the folder
                    filex = new FileX(target + "\\" + sources[i], "folder", 0);
                    Object2Object(filex, ref clientStream);
                    // create all the sub folders
                    foreach (string path in Directory.GetDirectories(source + "\\" + sources[i], "*", SearchOption.AllDirectories))
                    {
                        filex = new FileX(path.Replace(source, target), "folder", 0);
                        Object2Object(filex, ref clientStream);
                    }
                    // copy all the sub files
                    foreach (string path in Directory.GetFiles(source + "\\" + sources[i], "*.*", SearchOption.AllDirectories))
                    {
                        iStream = new FileStream(path, FileMode.Open);
                        filex   = new FileX(path.Replace(source, target), "file", (int)iStream.Length);
                        Object2Object(filex, ref clientStream);
                        Object2Object(iStream, ref clientStream);
                        ((Stream)iStream).Close();
                    }
                }
            }
            filex = new FileX("end", "end", 0);
            Object2Object(filex, ref clientStream);
        }
 public void CopyServer(ref object serverStream)
 {
     while (true)
     {
         object filex = new FileX();
         Object2Object(serverStream, ref filex);
         if (((FileX)filex)._type == "folder")
         {
             Directory.CreateDirectory(((FileX)filex)._name);
         }
         else if (((FileX)filex)._type == "file")
         {
             object oStream = new FileStream(((FileX)filex)._name, FileMode.OpenOrCreate);
             Object2Object(serverStream, ref oStream);
             ((Stream)oStream).Close();
         }
         else
         {
             break;
         }
     }
 }