/
FtpStorageFile.cs
36 lines (32 loc) · 1.1 KB
/
FtpStorageFile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.
using Files.Core.Storage;
using Files.Core.Storage.LocatableStorage;
using Files.Core.Storage.ModifiableStorage;
using Files.Core.Storage.NestedStorage;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace Files.App.Storage.FtpStorage
{
public sealed class FtpStorageFile : FtpStorable, IModifiableFile, ILocatableFile, INestedFile
{
public FtpStorageFile(string path, string name, IFolder? parent)
: base(path, name, parent)
{
}
/// <inheritdoc/>
public async Task<Stream> OpenStreamAsync(FileAccess access, CancellationToken cancellationToken = default)
{
using var ftpClient = GetFtpClient();
await ftpClient.EnsureConnectedAsync(cancellationToken);
if (access.HasFlag(FileAccess.Write))
return await ftpClient.OpenWrite(Path, token: cancellationToken);
else if (access.HasFlag(FileAccess.Read))
return await ftpClient.OpenRead(Path, token: cancellationToken);
else
throw new ArgumentException($"Invalid {nameof(access)} flag.");
}
}
}