Exemplo n.º 1
0
        private void ThreadFun_Upload_File(object obj)
        {
            SockInfo_U s    = (SockInfo_U)obj;
            FileStream file = s.file;
            Socket     sock = s.s;

            Upload_File(file, sock, file.Name.Substring(file.Name.LastIndexOf(@"\") + 1));
            // Console.WriteLine("asdfasdfasdf");
            sock.Close();
        }
Exemplo n.º 2
0
        private void ThreadFunUpload_Directory(object obj)
        {
            StructByte     S_B = new StructByte();
            SockInfo_U     s   = (SockInfo_U)obj;
            Directory_info d   = new Directory_info();
            List <string>  l   = new List <string>();

            d.name = s.di.Name;
            GetAllDirList(s.di.FullName, l, d);
            byte[] bu = new byte[270];
            string Root_directory_name = s.di.FullName.Substring(s.di.FullName.LastIndexOf(@"\") + 1);

            bu = S_B.StructToBytes(new info(Root_directory_name, (UInt32)d.size, 2, (UInt32)l.Count));
            s.s.Send(bu, bu.Length, SocketFlags.None);
            Thread.Sleep(1000);
            s.s.Receive(bu, SocketFlags.None);
            int i = BitConverter.ToInt32(bu, 0);

            Thread.Sleep(10);
            try
            {
                for (; i < l.Count; i++)
                {
                    string        name = l[i];
                    DirectoryInfo di   = new DirectoryInfo(name);
                    string        n    = name.Substring(name.IndexOf(Root_directory_name));
                    if (di.Attributes == FileAttributes.Directory)
                    {
                        bu = S_B.StructToBytes(new info(n, 0, 2, 1));
                        s.s.Send(bu, bu.Length, SocketFlags.None);
                    }
                    else if (di.Attributes == FileAttributes.Normal || di.Attributes == FileAttributes.Archive)
                    {
                        Upload_File(new FileStream((name), FileMode.Open, FileAccess.Read, FileShare.Read), s.s, n);
                    }
                }
                bu = S_B.StructToBytes(new info("asdf", 0, 0, 0));
                s.s.Send(bu, bu.Length, SocketFlags.None);
                s.s.Close();
            }
            catch (Exception)
            {
                ;
            }
            //  Console.WriteLine("asdf");
        }