Skip to content

Commit 12d2094

Browse files
fix: server without support MLST command
1 parent b777f21 commit 12d2094

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

src/TagBites.IO.Ftp/FtpFileSystemOperations.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,20 @@ private LinkInfo GetInfo(string fullName)
358358
{
359359
using (_locker.Lock())
360360
{
361-
if (!PrepareClient().IsConnected)
362-
PrepareClient().AutoConnect();
361+
var client = PrepareClient();
362+
if (!client.IsConnected)
363+
client.AutoConnect();
363364

364365
try
365366
{
366-
var item = PrepareClient().GetObjectInfo(fullName, true);
367+
if (fullName == "/")
368+
{
369+
// BUG WORKAROUND: IF file system doesn't support MLST command there is problem with root directory
370+
if (!client.HasFeature(FtpCapability.MLSD))
371+
return GetInfo(fullName, new FtpListItem("/", 0, FtpObjectType.Directory, DateTime.MinValue));
372+
}
373+
374+
var item = client.GetObjectInfo(fullName, true);
367375
return item != null ? GetInfo(fullName, item) : null;
368376
}
369377
catch (Exception e)
@@ -378,7 +386,15 @@ private async Task<LinkInfo> GetInfoAsync(string fullName)
378386
{
379387
try
380388
{
381-
var item = await (await PrepareClientAsync().ConfigureAwait(false)).GetObjectInfo(fullName, true).ConfigureAwait(false);
389+
var client = await PrepareClientAsync().ConfigureAwait(false);
390+
if (fullName == "/")
391+
{
392+
// BUG WORKAROUND: IF file system doesn't support MLST command there is problem with root directory
393+
if (!client.HasFeature(FtpCapability.MLSD))
394+
return GetInfo(fullName, new FtpListItem("/", 0, FtpObjectType.Directory, DateTime.MinValue));
395+
}
396+
397+
var item = await client.GetObjectInfo(fullName, true).ConfigureAwait(false);
382398
return item != null ? GetInfo(fullName, item) : null;
383399
}
384400
catch (Exception e)

0 commit comments

Comments
 (0)