Beispiel #1
0
 public void TestConnection()
 {
     using (var ftp = GetNewFtpsClient())
     {
         ftp.Open(Username, Password.ConvertToInsecureString());
     }
 }
Beispiel #2
0
 public void MakeDirectory(string name)
 {
     using (var ftp = GetNewFtpsClient())
     {
         ftp.Open(Username, Password.ConvertToInsecureString());
         ftp.MakeDirectory(name);
     }
 }
Beispiel #3
0
 public void DeleteFile(string fileName)
 {
     using (var ftp = GetNewFtpsClient())
     {
         ftp.Open(Username, Password.ConvertToInsecureString());
         ftp.ChangeDirectoryMultiPath(Directory);
         ftp.DeleteFile(fileName);
     }
 }
Beispiel #4
0
 public void UploadFile(string filePath)
 {
     using (var ftp = GetNewFtpsClient())
     {
         ftp.Open(Username, Password.ConvertToInsecureString());
         ftp.ChangeDirectoryMultiPath(Directory);
         ftp.PutFile(filePath, FileAction.Create);
     }
 }
Beispiel #5
0
 public void RenameDirectory(string oldName, string newName)
 {
     using (var ftp = GetNewFtpsClient())
     {
         ftp.Open(Username, Password.ConvertToInsecureString());
         ftp.ChangeDirectoryMultiPath(Directory);
         ftp.Rename(oldName, newName);
     }
 }
Beispiel #6
0
 public IEnumerable <ServerItem> ListDirectoriesAndFiles(string path, bool recursive)
 {
     using (var ftp = GetNewFtpsClient())
     {
         ftp.Open(Username, Password.ConvertToInsecureString());
         var items = recursive ? ftp.GetDirListDeep(path) : ftp.GetDirList(path);
         return(items.Select(f => f.ToServerItem()));
     }
 }
Beispiel #7
0
 public bool IsExisting(string directoryPath, string destinationName)
 {
     using (var ftp = GetNewFtpsClient())
     {
         ftp.Open(Username, Password.ConvertToInsecureString());
         ftp.ChangeDirectoryMultiPath(directoryPath);
         return(ftp.Exists(directoryPath, destinationName));
     }
 }
Beispiel #8
0
 public void UploadPackage(string packagePath, string packageVersion)
 {
     _packageFtpsClient = GetNewFtpsClient();
     _packageFtpsClient.TransferProgress      += TransferProgressChangedEventHandler;
     _packageFtpsClient.PutFileAsyncCompleted += UploadPackageFinished;
     _packageFtpsClient.Open(Username, Password.ConvertToInsecureString());
     _packageFtpsClient.ChangeDirectoryMultiPath(Directory);
     _packageFtpsClient.MakeDirectory(packageVersion);
     _packageFtpsClient.ChangeDirectory(packageVersion);
     _packageFtpsClient.PutFileAsync(packagePath, FileAction.Create);
     _uploadPackageResetEvent.WaitOne();
     _packageFtpsClient.Close();
     _uploadPackageResetEvent.Reset();
 }
Beispiel #9
0
        public void MoveContent(string directory, string aimPath)
        {
            foreach (var item in ListDirectoriesAndFiles(directory, false)
                     .Where(
                         item => item.FullPath != aimPath && item.FullPath != aimPath.Substring(aimPath.Length - 1)))
            {
                using (var ftp = GetNewFtpsClient())
                {
                    ftp.Open(Username, Password.ConvertToInsecureString());

                    Guid guid; // Just for the out-reference of TryParse
                    if (item.ItemType == ServerItemType.Directory && UpdateVersion.IsValid(item.Name))
                    {
                        ftp.ChangeDirectoryMultiPath(aimPath);
                        if (!IsExisting(aimPath, item.Name))
                        {
                            ftp.MakeDirectory(item.Name);
                        }
                        ftp.ChangeDirectoryMultiPath(item.Name);

                        MoveContent(item.FullPath, $"{aimPath}/{item.Name}");
                        DeleteDirectory(item.FullPath);
                    }
                    else if (item.ItemType == ServerItemType.File &&
                             (item.Name == "updates.json" || item.Name == "statistics.php" || Guid.TryParse(item.Name.Split('.')[0], out guid)))
                    // Second condition determines whether the item is a package-file or not
                    {
                        if (!IsExisting(aimPath, item.Name))
                        {
                            // "MoveFile"-method damages the files, so we do it manually with a work-around
                            ftp.MoveFile(item.FullPath, $"{aimPath}/{item.Name}");

                            /*string localFilePath = Path.Combine(Path.GetTempPath(), item.Name);
                             * ftp.GetFile(item.FullPath, localFilePath, FileAction.Create);
                             * ftp.PutFile(localFilePath, $"{aimPath}/{item.Name}",
                             *  FileAction.Create);
                             * File.Delete(localFilePath);*/
                        }
                    }
                }
            }
        }
Beispiel #10
0
 public bool IsExisting(string destinationName)
 {
     using (var ftp = GetNewFtpsClient())
     {
         ftp.Open(Username, Password.ConvertToInsecureString());
         ftp.ChangeDirectoryMultiPath(Directory);
         string nameList = null;
         try
         {
             nameList = ftp.GetNameList(destinationName);
         }
         catch (Exception ex)
         {
             if (ex.Message.Contains("No such file or directory") || ex.Message.Contains("Directory not found"))
             {
                 return(false);
             }
         }
         return(!string.IsNullOrEmpty(nameList));
     }
 }
Beispiel #11
0
        public void DeleteDirectory(string directoryPath)
        {
            using (var ftp = GetNewFtpsClient())
            {
                IEnumerable <ServerItem> items = ListDirectoriesAndFiles(directoryPath, true);
                ftp.Open(Username, Password.ConvertToInsecureString());
                foreach (var item in items)
                {
                    switch (item.ItemType)
                    {
                    case ServerItemType.Directory:
                        DeleteDirectory($"/{directoryPath}/{item.Name}/");
                        break;

                    case ServerItemType.File:
                        DeleteFile(directoryPath, item.Name);
                        break;
                    }
                }
                ftp.DeleteDirectory(directoryPath);
            }
        }