예제 #1
0
        /// <summary>
        /// Renomme un fichier. file est le fichier a renommer, newName est son nouveau nom
        /// </summary>
        /// <param name="path"></param>
        /// <param name="newName"></param>
        public static void Rename(FtpClientFile file, string newName)
        {
            string newPath = file.path.Substring(0, file.path.Length - 1);

            newPath = newPath.Substring(0, newPath.LastIndexOf('/') + 1) + newName;
            client.Rename(file.path, newPath);
        }
예제 #2
0
파일: GUI.cs 프로젝트: KubbyDev/ClientFTP
        public static void MoveToDirectory(FtpClientFile newDirectory)
        {
            currentDirectory = newDirectory;
            parentDirectory  = GetParentDirectory();

            selection = null;
            GUI.RefreshFileList();
            form.SetPathTextBox(newDirectory.path);
        }
예제 #3
0
        /// <summary>
        /// Renvoie une liste des fichiers/dossiers presents dans le dossier specifie
        /// </summary>
        /// <param name="inFolder"></param>
        /// <returns></returns>
        public static List <FtpClientFile> GetAllFiles(FtpClientFile inFolder)
        {
            if (!inFolder.isDirectory)
            {
                return(new List <FtpClientFile>());
            }

            return(client.GetListing(inFolder.path).Select(file => new FtpClientFile(file.FullName, file.Type == FtpFileSystemObjectType.Directory)).ToList <FtpClientFile>());
        }
예제 #4
0
        /// <summary> fileToUpload est le fichier local,
        /// destinationFolder est le dossier destination sur le serveur </summary>
        /// <param name="fileToUpload"></param>
        /// <param name="destinationFolder"></param>
        public static void UploadFile(FtpClientFile fileToUpload, FtpClientFile destinationFolder = null)
        {
            //Si le dossier de destination n'est pas specifie on prend le dossier home
            if (destinationFolder == null)
            {
                destinationFolder = FtpClientFile.serverHomeFolder;
            }

            //Si le dossier de destination n'est pas un dossier on devient tout rouge
            if (!destinationFolder.isDirectory)
            {
                Console.Error.WriteLine("The destination must be a folder !");
                return;
            }

            //Si le dossier de destination n'existe pas on le cree
            client.CreateDirectory(destinationFolder.path);

            //Si le fichier de depart est un dossier on upload tous les fichiers dedans
            if (fileToUpload.isDirectory)
            {
                foreach (FtpClientFile file in FileManager.GetFilesInFolder(fileToUpload))
                {
                    UploadFile(file, new FtpClientFile(destinationFolder.path + fileToUpload.name, true));
                }

                return;
            }

            //Check si le fichier existe deja
            string filePath = destinationFolder.path + fileToUpload.name;

            if (client.FileExists(filePath))
            {
                string GetNewPath(int i)
                {
                    int dotIndex = fileToUpload.name.LastIndexOf('.');

                    return(destinationFolder.path + fileToUpload.name.Substring(0, dotIndex) + " (" + i + ")" + fileToUpload.name.Substring(dotIndex));
                }

                int index = 1;
                filePath = GetNewPath(index);

                while (client.FileExists(filePath))
                {
                    index++;
                    filePath = GetNewPath(index);
                }
            }

            //Upload le fichier
            Console.WriteLine("Uploading " + fileToUpload.name + " ...");
            client.UploadFile(fileToUpload.path, filePath);
        }
예제 #5
0
        /// <summary>
        /// Cree un dossier a l'emplacement specifie
        /// </summary>
        /// <param name="path"></param>
        /// <param name="name"></param>
        public static void CreateDirectory(FtpClientFile path, string name)
        {
            //Si le dossier de destination n'est pas un dossier on devient tout rouge
            if (!path.isDirectory)
            {
                Console.Error.WriteLine("The path must be a folder !");
                return;
            }

            client.CreateDirectory(path.path + name);
        }
예제 #6
0
 /// <summary>
 /// Supprime un fichier
 /// </summary>
 /// <param name="file"></param>
 public static void Delete(FtpClientFile file)
 {
     if (file.isDirectory)
     {
         client.DeleteDirectory(file.path);
     }
     else
     {
         client.DeleteFile(file.path);
     }
 }
예제 #7
0
파일: GUI.cs 프로젝트: KubbyDev/ClientFTP
 public static void ChangeSelection(FtpClientFile newSelection)
 {
     selection = newSelection;
     if (selection != null)
     {
         form.SetPathTextBox(selection.path);
     }
     else
     {
         form.SetPathTextBox(currentDirectory.path);
     }
 }
예제 #8
0
파일: GUI.cs 프로젝트: KubbyDev/ClientFTP
 public static void Init()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     form             = new Form1();
     selection        = null;
     parentDirectory  = null;
     currentDirectory = null;
     clientFiles      = new List <FtpClientFile>();
     form.SetPathTextBox("");
     Application.Run(form);
 }
예제 #9
0
        /// <summary>
        /// Renvoie tous les fichiers et dossiers dans le dossier specifie
        /// </summary>
        /// <param name="folder"></param>
        /// <returns></returns>
        public static FtpClientFile[] GetFilesInFolder(FtpClientFile folder)
        {
            if (!folder.isDirectory)
            {
                return new FtpClientFile[] { }
            }
            ;

            return(Directory.GetDirectories(folder.path).Select(path => new FtpClientFile(path, true))     //Recupere tous les dossiers dans le dossier
                   .Concat(Directory.GetFiles(folder.path).Select(path => new FtpClientFile(path, false))) //Recupere tous les fichiers dans le dossier
                   .ToArray());
        }
예제 #10
0
파일: GUI.cs 프로젝트: KubbyDev/ClientFTP
        private static void ShowFile(FtpClientFile file)
        {
            string fileType = (file.isDirectory)? "directory" : "file";

            if (file != parentDirectory)
            {
                form.fileGrid.Rows.Add(fileType, file.name);
            }
            else
            {
                form.fileGrid.Rows.Add(fileType, "../");
            }
        }
예제 #11
0
        /// <summary>
        /// Bouge un fichier. file est le fichier a bouger, newFolder est le dossier de destination
        /// </summary>
        /// <param name="file"></param>
        /// <param name="newFolder"></param>
        public static void Move(FtpClientFile file, FtpClientFile newFolder)
        {
            //Si le dossier de destination n'est pas un dossier on devient tout rouge
            if (!newFolder.isDirectory)
            {
                Console.Error.WriteLine("The new folder must be a folder !");
                return;
            }

            //Si le dossier de destination n'existe pas on le cree
            client.CreateDirectory(newFolder.path);

            client.MoveFile(file.path, newFolder.path + file.GetName());
        }
예제 #12
0
        /// <summary> fileToDownload est le fichier sur le serveur,
        /// destinationFolder est le dossier de destination en local </summary>
        /// <param name="fileToDownload"></param>
        /// <param name="destinationFolder"></param>
        public static void DownloadFile(FtpClientFile fileToDownload, FtpClientFile destinationFolder)
        {
            //Si le dossier de destination n'est pas un dossier on devient tout rouge
            if (!destinationFolder.isDirectory)
            {
                Console.Error.WriteLine("The destination must be a folder !");
                return;
            }

            //Si le dossier de destination n'existe pas on le cree
            FileManager.CreateDirectory(destinationFolder.path);

            //Si le fichier de depart est un dossier on download tous les fichiers dedans
            if (fileToDownload.isDirectory)
            {
                foreach (FtpClientFile file in GetAllFiles(fileToDownload))
                {
                    DownloadFile(file, new FtpClientFile(destinationFolder.path + fileToDownload.name, true));
                }

                return;
            }

            //Check si le fichier existe deja
            string filePath = destinationFolder.path + fileToDownload.name;

            if (FileManager.FileExists(filePath))
            {
                string GetNewPath(int i)
                {
                    int dotIndex = fileToDownload.name.LastIndexOf('.');

                    return(destinationFolder.path + fileToDownload.name.Substring(0, dotIndex) + " (" + i + ")" + fileToDownload.name.Substring(dotIndex));
                }

                int index = 1;
                filePath = GetNewPath(index);

                while (FileManager.FileExists(filePath))
                {
                    index++;
                    filePath = GetNewPath(index);
                }
            }

            //Download le fichier
            Console.WriteLine("Downloading " + fileToDownload.name + " ...");
            client.DownloadFile(filePath, fileToDownload.path);
        }
예제 #13
0
파일: GUI.cs 프로젝트: KubbyDev/ClientFTP
 public static void Disconnect()
 {
     if (!Connection.IsConnectionActive())
     {
         return;
     }
     try
     {
         Connection.Close();
         WriteLineToConsole("Disconnected from the server.");
     }
     catch (Exception)
     {
         WriteLineToConsole("Could not disconnect from the server.");
     }
     selection        = null;
     currentDirectory = null;
     clientFiles      = null;
     form.SetPathTextBox("");
 }