Beispiel #1
0
        /// <summary>
        /// This will init a local directory.
        /// </summary>
        /// <param name="path"></param>
        public void InitLocal(string path,ClientThread client, ref RichTextBox richTextBox1)
        {
            this.client = client;
            this.log = richTextBox1;
            IsRemote = false;
            FTPDirectory dir = new FTPDirectory(path, false, null);
            dir.GetDirs();
            dir.GetChildrenDirs();

            // Configure the first tree
            treeListView1.CanExpandGetter = delegate(object x)
            {
                return ((FTPDirectory)x).Children != null;
            };
            treeListView1.ChildrenGetter = delegate(object x) { return ((FTPDirectory)x).GetChildren(); };

            treeListView1.Roots = dir.Children;

            treeListView1.IsSimpleDragSource = true;
            treeListView1.IsSimpleDropSink = true;
        }
Beispiel #2
0
        public FTPDirectory(string path, bool IsFile, FTPDirectory parent = null)
        {
            id = Guid.NewGuid().ToString();
            if (path.Split('\\').Length == 0) { this.Name = path; }
            else
            {
                this.Name = path.Split('\\')[path.Split('\\').Length - 1];
            }
            this.IsFile = IsFile;
            this.Path = path;
            if (parent != null)
            {
                Parent = parent;
            }

            //sort out the directories.
            if (IsFile)
            {
                FileInfo i = new FileInfo(path);
                this.Size = (int) (i.Length / 1024); //get mb
                this.kbSize =(int) i.Length;
            }
        }
Beispiel #3
0
 /// <summary>
 /// Send a whole folder to a remote client
 /// </summary>
 /// <param name="ftp">The directory to send</param>
 /// <param name="pathOfFile">The location of the directory</param>
 /// <param name="pathToGo">Where to store it in the remote machine</param>
 /// <param name="client">The current client</param>
 /// <param name="oppositeFolderControl">The folder control that dropped it</param>
 private void SendFolderToClient(FTPDirectory ftp, string pathOfFile, string pathToGo, ClientThread client, FolderControl oppositeFolderControl)
 {
     if (ftp.IsFile)
     {
         pathToGo = pathToGo.Replace("\\", "\\\\");
         oppositeFolderControl.client.SendFileToOtherClient(pathOfFile, ftp.kbSize, pathToGo, client);
     }
     else
     {
         ftp.GetChildren();
         foreach (FTPDirectory f in ftp.Children)
         {
             SendFolderToClient(f, f.Path, pathToGo + "\\" + f.Name, client, oppositeFolderControl);
         }
     }
 }
Beispiel #4
0
        private void SendFolder(FTPDirectory ftp, ClientThread client, string pathToGo, FTP par)
        {
            if (Directory.Exists(ftp.Path))
            {
                ftp.GetChildren();
                foreach (FTPDirectory f in ftp.Children)
                {
                    SendFolder(f, client, pathToGo + "\\\\" + f.Name, par);
                }
            }
            else
            {

                Messaging.SendCommand("RemoteAcceptFTP(" + client.GetPort() + ",'" + pathToGo + "', " + new FileInfo(ftp.Path).Length + ");", client.GetClientSocket());
                //Messaging.RemoteAcceptFTP(client.GetClientSocket(), pathToGo);
                Messaging.FTPFile(ftp.Path, client.GetClientSocket());
                log.Text += ("\nFile successfully sent.\n");
                par.Refresh();
            }
        }
Beispiel #5
0
        public static void SendFTPDirectory(FTPDirectory obj, TcpClient Socket)
        {
            NetworkStream stream = Socket.GetStream();
            BinaryFormatter bf = new BinaryFormatter();
            MemoryStream ms = new MemoryStream();
            bf.Serialize(ms, obj);
            byte[] buffer = ms.ToArray();
            System.Threading.Thread.Sleep(500);
            Socket.Client.SendTo(buffer, Socket.Client.RemoteEndPoint);
            // stream.Write(buffer, 0, buffer.Length);
            //stream.Flush();

            Console.WriteLine("BUFFER FOR SENT OBJECT WAS :: " + buffer);
        }
Beispiel #6
0
 public FTPDirectory InitFTPDirectory(string path)
 {
     dir = new FTPDirectory(path, false, null);
     dir.GetDirs();
     dir.GetChildrenDirs();
     return dir;
 }
Beispiel #7
0
        public void GetDirs()
        {
            if (!IsFile)
            {
                Children = new List<FTPDirectory>();
                try
                {
                    foreach (string d in Directory.GetDirectories(Path))
                    {
                        try
                        {
                            FTPDirectory temp = new FTPDirectory(d, false, this);

                            Children.Add(temp);
                        }
                        catch (IOException e) { Console.WriteLine(d); }
                    }

                    foreach (string d in Directory.GetFiles(Path))
                    {
                        try
                        {
                            FTPDirectory temp = new FTPDirectory(d, true, this);

                            Children.Add(temp);
                        }
                        catch (Exception e) { Console.WriteLine(d); }
                    }
                }
                catch (System.Exception excpt)
                {
                }
            }
        }