public FileSystemUtilities(VirtualDirectorySecurity vds, Server server, Service service, CommandContext ctx) { FileSystem = server.FileSystemService; VirtualDirectorySecurity = vds; Server = server; Service = service; CommandContext = ctx; }
public FileSystemUtilities(VirtualDirectorySecurity vds, Server server, CommandContext ctx) { FileSystem = server.FileSystemService; VirtualDirectorySecurity = vds; Server = server; Service = new Service { WorkingDirectory = "/", RootDirectory = "/", Executable = "/" }; CommandContext = ctx; }
public async Task DownloadFile(FileInfo file) { var server = new Server(Service.ServerId); var directorySecurity = new TCAdmin.SDK.VirtualFileSystem.VirtualDirectorySecurity { Permissions = Permission.Read | Permission.Write | Permission.Delete, PermissionType = PermissionType.Root, RelativeExecutable = Strings.ReplaceCaseInsensitive(Service.Executable, Service.RootDirectory, string.Empty), VirtualDirectoryName = Service.ConnectionInfo, RootPhysicalPath = Service.RootDirectory, RealPhysicalPath = TCAdmin.SDK.Misc.FileSystem.FixAbsoluteFilePath(Service.RootDirectory, server.OperatingSystem), ServerId = server.ServerId }; var download = new RemoteDownload(server) { DirectorySecurity = directorySecurity, FileName = file.FullName }; if (file.Length / 1024 > 8) { await CommandContext.RespondAsync( embed : EmbedTemplates.CreateSuccessEmbed( $"[<{download.GetDownloadUrl()}>](**Click here to download {file.Name}**)")); } else { using (var client = new WebClient()) { client.DownloadFileCompleted += delegate { CommandContext.RespondWithFileAsync(file.Name); }; client.DownloadFileAsync(new Uri(download.GetDownloadUrl()), file.Name); } } await Task.Delay(3000); File.Delete(file.Name); }