예제 #1
0
        public bool Rename(IFileSystemItem item, string newName, bool overwrite = false)
        {
            FtpExists exists      = overwrite ? FtpExists.Overwrite : FtpExists.Skip;
            string    currentPath = item.GetUri().AbsolutePath;

            try
            {
                if (item.IsDirectory())
                {
                    string upperPath = IO.Path.GetFullPath(IO.Path.Combine(currentPath, ".."));
                    string destUri   = IO.Path.GetFullPath(IO.Path.Combine(upperPath, newName));
                    return(client.MoveDirectory(currentPath, destUri, exists));
                }
                else
                {
                    string destUri = IO.Path.GetFullPath(IO.Path.Combine(currentPath, newName));
                    return(client.MoveFile(item.GetUri().AbsoluteUri, destUri, exists));
                }
            }
            catch (Exception e)
            {
                ExceptionHandler.LogException(e);
            }
            return(false);
        }
예제 #2
0
 public bool AddItem(IFileSystemItem item, Directory directory, bool overwrite)
 {
     try
     {
         FtpExists exists = overwrite ? FtpExists.Overwrite : FtpExists.Skip;
         if (item.IsDirectory())
         {
             client.CreateDirectory(IO.Path.Combine(directory.GetUri().AbsolutePath, item.Name));
             List <IO.FileInfo> fileInfos = new List <IO.FileInfo>();
             foreach (IFileSystemItem subitem in (item as Directory).EnumerateChildren())
             {
                 fileInfos.Add(subitem.FileInfo);
             }
             int uploaded = client.UploadFiles(
                 fileInfos,
                 directory.GetUri().AbsolutePath,
                 exists,
                 createRemoteDir: true);
             return(uploaded == fileInfos.Count);
         }
         else
         {
             return(AddFile(item as File, directory, overwrite));
         }
     }
     catch (Exception e)
     {
         ExceptionHandler.LogException(e);
     }
     return(false);
 }
예제 #3
0
 public bool Delete(IFileSystemItem item)
 {
     try
     {
         if (item.IsDirectory())
         {
             client.DeleteDirectory(item.GetUri().AbsolutePath);
             return(!client.DirectoryExists(item.GetUri().AbsoluteUri));
         }
         else
         {
             client.DeleteFile(item.GetUri().AbsoluteUri);
             return(!FileExists(item.GetUri().AbsoluteUri));
         }
     }
     catch (Exception e)
     {
         ExceptionHandler.LogException(e);
     }
     return(false);
 }
예제 #4
0
        public bool Copy(IFileSystemItem item, Directory directory, bool overwrite)
        {
            FtpExists exists = overwrite ? FtpExists.Overwrite : FtpExists.Skip;

            try
            {
                if (item.IsDirectory())
                {
                    client.CreateDirectory(IO.Path.Combine(directory.GetUri().AbsolutePath, item.Name));
                }
                else
                {
                    IO.MemoryStream stream = GetFileStream(item as File);
                    return(client.Upload(stream, directory.GetUri().AbsolutePath, exists));
                }
            }
            catch (Exception e)
            {
                ExceptionHandler.LogException(e);
            }
            return(false);
        }
예제 #5
0
        public bool Move(IFileSystemItem item, Directory destDirectory, bool overwrite = false)
        {
            FtpExists exists   = overwrite ? FtpExists.Overwrite : FtpExists.Skip;
            string    destPath = destDirectory.GetUri().AbsolutePath;

            try
            {
                if (item.IsDirectory())
                {
                    return(client.MoveDirectory(item.GetUri().AbsolutePath, destPath, exists));
                }
                else
                {
                    return(client.MoveFile(item.GetUri().AbsoluteUri, destPath, exists));
                }
            }
            catch (Exception e)
            {
                ExceptionHandler.LogException(e);
            }
            return(false);
        }