//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------



        public void GenerateTreeView(ExtendedTreeNode mainNode, string pathServer, FTPConnection2 myFTPConnection)
        {
            using (Session myConnection = new Session())
            {
                myConnection.Open(myFTPConnection.MyConnectionOptions);
                Generate(myConnection, mainNode, pathServer);
            }
        }
        //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

        public List <TreeNode> ExpandTreeNode(ExtendedTreeNode nodeToExpand, FTPConnection2 myFTPConnection)
        {
            List <TreeNode> nodesToReturn = new List <TreeNode>();


            using (Session myConnection = new Session())
            {
                myConnection.Open(myFTPConnection.MyConnectionOptions);
                RemoteDirectoryInfo directoryInfo = myConnection.ListDirectory(nodeToExpand.Name);

                foreach (RemoteFileInfo file in directoryInfo.Files)
                {
                    if (file.Name != ".." && file.IsDirectory)
                    {
                        ExtendedTreeNode folderNode = new ExtendedTreeNode(file.Name);
                        folderNode.Text = file.Name;

                        if (nodeToExpand.Name.Equals("/"))
                        {
                            folderNode.Name = "/" + file.FullName;
                        }
                        else
                        {
                            folderNode.Name = file.FullName;
                        }

                        folderNode.Tag                = "Directory";
                        folderNode.ImageIndex         = 2;
                        folderNode.SelectedImageIndex = 2;
                        Generate(myConnection, folderNode, folderNode.Name);
                        nodesToReturn.Add(folderNode);
                    }
                }
            }


            return(nodesToReturn);
        }
        //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------



        public static void GeneriranjeNovihTreeNodovaPrilikomUploada(string localPath, string serverPath, FTPConnection2 myFTPConnection, TreeView treeview)
        {
            string path_newFileOrFolder = serverPath + "/" + Path.GetFileName(localPath);

            if (treeview.Nodes.Find(path_newFileOrFolder, true).Count() != 0) // prilikom overwritea nodovi vec postoje pa ih ne treba ponovo generirati
            {
                treeview.Nodes.Find(path_newFileOrFolder, true)[0].Remove();
            }

            FileAttributes localFileAttribute = File.GetAttributes(localPath);

            if (localFileAttribute == FileAttributes.Directory)
            {
                ExtendedTreeNode rootNode = (ExtendedTreeNode)treeview.Nodes.Find(serverPath, true)[0];
                AddingNewTreeNodes(rootNode, localPath, serverPath);
            }
        }
        //********************************************************************************************************************
        //                                                  S E R V E R
        //********************************************************************************************************************

        public static void ShowContentServer(ListView listViewContentServer, string path, FTPConnection2 myConnection, IWin32Window owner)
        {
            listViewContentServer.Items.Clear();//brise prethodni prikaz listviewa

            try
            {
                List <string[]> subdirectories1 = myConnection.GetDirectoriesAndFiles(path);

                foreach (string[] dir in subdirectories1)
                {
                    ListViewItem lvi = new ListViewItem(dir[0]);                            // ime filea/dir                        item[0] = fileInfo.Name;
                    lvi.SubItems.Add(Convert.ToString(Convert.ToInt64(dir[1]) / 1024));     // velicina                             item[1] = Convert.ToString(fileInfo.Length);
                    lvi.SubItems.Add(dir[2]);                                               // ekstenzija                           item[2] = Path.GetExtension(fileInfo.Name);
                    lvi.SubItems.Add(dir[3]);                                               // last modified                        item[3] = Convert.ToString(fileInfo.LastWriteTime);
                    lvi.Name = dir[4];                                                      // da li je direktorij?                 item[4] = Convert.ToString(fileInfo.IsDirectory);
                    lvi.Tag  = dir[5];                                                      // kompletni path filea/dir             item[5] = fileInfo.FullName;


                    if (dir[4].Equals("True"))     // radi se o folderu
                    {
                        lvi.ImageIndex = 1;
                    }
                    else
                    {
                        if (((Form_Glavna)owner).imageList_ListViewContent.Images.ContainsKey(dir[2]))
                        {
                            lvi.ImageKey = dir[2];
                        }
                        else
                        {
                            try
                            {
                                Icon fileIcon = Icons.IconFromExtension(dir[2], Icons.SystemIconSize.Small);
                                ((Form_Glavna)owner).imageList_ListViewContent.Images.Add(dir[2], fileIcon);
                                lvi.ImageKey = dir[2];
                            }
                            catch (Exception)
                            {
                                lvi.ImageIndex = 2;
                            }
                        }
                    }

                    listViewContentServer.Items.Add(lvi);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }