sparkeh9 / CoreFTP

An FTP library written in C# with no external dependencies
MIT License
108 stars 34 forks source link

Random System.IndexOutOfRangeException when changing directory #42

Open qaramelus opened 5 years ago

qaramelus commented 5 years ago

Hi there,

I've got a nightly process running that uses your library. Many thanks for making it available. However, this line https://github.com/sparkeh9/CoreFTP/blob/master/src/CoreFtp/FtpClient.cs#L170 randomly throws an exception:

System.IndexOutOfRangeException: Index was outside the bounds of the array. at CoreFtp.FtpClient.ChangeWorkingDirectoryAsync(String directory) at CoreFtp.FtpClient.CreateDirectoryStructureRecursively(IReadOnlyCollection`1 directories, Boolean isRootedPath) at CoreFtp.FtpClient.OpenFileWriteStreamAsync(String fileName)

For I guess the response does not always contain a double quote.

This is totally random, I upload one file every night (with the same filename format, to the same target ftp directory) and sometimes the log shows the exception and sometimes all goes smoothly.

For now, I retry the upload operation with Polly (http://www.thepollyproject.org/) and has always succeeded at the first retry.

HekmatBeigverdi commented 2 years ago

I Use login ftp for each change directory and it's work properly. For example:

                    await ftpClient.LoginAsync();
                    using (var writeStream = await ftpClient.OpenFileWriteStreamAsync("photos/customer/original/" + fileName))
                    {
                        var fileReadStream = fileinfoOriginal.OpenRead();
                        await fileReadStream.CopyToAsync(writeStream);
                    }
                    await ftpClient.LoginAsync();
                    using (var writeStream = await ftpClient.OpenFileWriteStreamAsync("photos/customer/thumb/" + fileName))
                    {
                        var fileReadStream = fileinfoThumb.OpenRead();
                        await fileReadStream.CopyToAsync(writeStream);
                    }