Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot OpenFileReadStreamAsync #43

Open
wnsan opened this issue Jun 25, 2019 · 0 comments
Open

Cannot OpenFileReadStreamAsync #43

wnsan opened this issue Jun 25, 2019 · 0 comments

Comments

@wnsan
Copy link

wnsan commented Jun 25, 2019

when I connect to FTP server it connect to high port (50000+) and stuck when OpenFileReadStreamAsync after login

            using (var ftpClient = new FtpClient(new FtpClientConfiguration
            {
                Host = PrPath,
                Username = ftpLogin,
                Password = ftpLogin,
                BaseDirectory = baseDirectory,
                SslProtocols = System.Security.Authentication.SslProtocols.None,
                
            }))
            {
                var fileinfo = new FileInfo(localpath);
                Console.WriteLine("login");
                await ftpClient.LoginAsync();
                Console.WriteLine("after login");
                byte[] existsData;
                try
                {
                    using (var readStream = await ftpClient.OpenFileReadStreamAsync(fileUpload))

                    {
                        Console.WriteLine("read remote");
                        existsData = ReadToEnd(readStream);
                        readStream.Dispose();
                        Console.WriteLine("after read remote");
                    }
                }
                catch (Exception readException)
                {
                    Console.WriteLine("first exception");
                    Console.WriteLine(readException.Message);
                    existsData = null;
                }
                using (var writeStream = await ftpClient.OpenFileWriteStreamAsync(fileUpload))
                {
                    Console.WriteLine("write stream");
                    var fileReadStream = fileinfo.OpenRead();
                    if (existsData != null)
                    {
                        var existReadStream = new MemoryStream(existsData);
                        await existReadStream.CopyToAsync(writeStream);
                    }
                    await fileReadStream.CopyToAsync(writeStream);
                    writeStream.Dispose();
                    fileReadStream.Dispose();
                    Console.WriteLine("after write stream");
                }
                ftpClient.Dispose();
                System.IO.File.Delete(localpath);

            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        return 1;

it throw a connection attempt fail at XXX.XXX.XXX.XXX:51320 (high port) how can I fix this thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant