private static async Task RunWithGoogleDriveUser(string[] args, TestFtpServerOptions options) { options.Validate(); if (args.Length != 2) { throw new Exception("This command requires two arguments: <CLIENT-SECRETS-FILE> <USERNAME>"); } var clientSecretsFile = args[0]; var userName = args[1]; UserCredential credential; using (var secretsSource = new FileStream(clientSecretsFile, FileMode.Open)) { var secrets = GoogleClientSecrets.Load(secretsSource); credential = await GoogleWebAuthorizationBroker.AuthorizeAsync( secrets.Secrets, new[] { DriveService.Scope.DriveFile, DriveService.Scope.Drive }, userName, CancellationToken.None); if (options.RefreshToken) { await credential.RefreshTokenAsync(CancellationToken.None); } } var services = CreateServices(options) .AddFtpServer(sb => Configure(sb, options).UseGoogleDrive(credential)); Run(services, options); }
private static void RunWithFileSystem(string[] args, TestFtpServerOptions options) { options.Validate(); var rootDir = args.Length != 0 ? args[0] : Path.Combine(Path.GetTempPath(), "TestFtpServer"); var services = CreateServices(options) .Configure <DotNetFileSystemOptions>(opt => opt.RootPath = rootDir) .AddFtpServer(sb => Configure(sb, options).UseDotNetFileSystem()); Run(services, options); }
private static void RunWithGoogleDriveService(string[] args, TestFtpServerOptions options) { options.Validate(); if (args.Length != 1) { throw new Exception("This command requires one argument: <SERVICE-CREDENTIAL-FILE>"); } var serviceCredentialFile = args[0]; var credential = GoogleCredential .FromFile(serviceCredentialFile) .CreateScoped(DriveService.Scope.Drive, DriveService.Scope.DriveFile); var services = CreateServices(options) .AddFtpServer(sb => Configure(sb, options).UseGoogleDrive(credential)); Run(services, options); }