Search code examples
c#ftpasync-awaitstreamreader

Streamreader Throwing ObjectDisposed Exception When Reading FTP DirectoryList With Spaces


I am working on a simple FTP application that reads the server inventory of a server and pulls down new files. In order to do this, I must read the directory list for its contents. The FTP ListDirectoryDetails works perfectly when the filenames and/or subdirectory names does not contain white space. However, if the directory has white space (i.e. spaces in the name), my readers throws an ObjectDisposed exception. The stack trace contains no user code besides the method below (everything other method call is in the framework).

I have googled and googled and googled some more without luck explaining this exception. Any assistance would be greatly appreciated! Thanks!

public async Task<List<string>> ListDirectoryDetailsAsync()
    {
        var list = new List<string>();
        var request = CreateRequest(WebRequestMethods.Ftp.ListDirectoryDetails);

        using (var response = (FtpWebResponse)await request.GetResponseAsync())
        using (var reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
        {
            while (!reader.EndOfStream)
            {
                list.Add(reader.ReadLine());
            }
        }
        return list;
    }

Solution

  • I have tried your code locally against the FileZilla Server (version 0.9.57 beta). Your code read directory names with white spaces very well. I assume your problem is specific to your data or environment. Capturing the network traffic might give some insight.