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

FTP Upload Issue After Updating to .Net Core 3.1 #46950

Closed
d-daniel-de-sousa opened this issue Dec 30, 2020 · 7 comments
Closed

FTP Upload Issue After Updating to .Net Core 3.1 #46950

d-daniel-de-sousa opened this issue Dec 30, 2020 · 7 comments
Milestone

Comments

@d-daniel-de-sousa
Copy link

d-daniel-de-sousa commented Dec 30, 2020

Issue Title

FTP Upload Issue After Updating to .Net Core 3.1

General

Version: .Net Core 3.1
OS: Windows
Solution Deployed: Web App Azure
Using Swagger.
Vnet

After Updating the Net Core Version from 2.1 to 3.1 the method to upload a file just stop working after deployed on Azure Web App.

If I Deploy it with a later version (2.1) it starts to work again.

Exception/error

Exception thrown: 'System.Net.WebException' in System.Net.Requests.dll
Unable to connect to remote server

image
image

Code

        public async Task<string> UploadFileFTP(string file)
        {
             FtpConfig ftpConfig = LightConfigurator.Config<FtpConfig>("FtpConfig");           

            FileInfo fileInfo = new FileInfo(file);
            Uri serverUri = new Uri(ftpConfig.Server + ":" + ftpConfig.Port + ftpConfig.Folder + fileInfo.Name);
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
            request.Method = WebRequestMethods.Ftp.UploadFile;
            request.Credentials = new NetworkCredential(ftpConfig.User, ftpConfig.Password);
            request.Proxy = null;
            request.UseBinary = true;
            request.ContentLength = fileInfo.Length;
            using (FileStream fs = fileInfo.OpenRead())
            {
                byte[] buffer = new byte[2048];
                int bytesSent = 0;
                int bytes = 0;
                using (Stream stream = request.GetRequestStream())
                {
                    while (bytesSent < fileInfo.Length)
                    {
                        bytes = fs.Read(buffer, 0, buffer.Length);
                        stream.Write(buffer, 0, bytes);
                        bytesSent += bytes;
                    }
                }
            }

            RegisterEvents.Register(ActionEnum.FPT_UPLOADING, "UploadFileFTP", $"Concluída a subida no FTP.");

            return "success";
        }
@scalablecory
Copy link
Contributor

Can you confirm the server is up and responding? It seems like it can't connect.

Do you know if the same happens in .NET 5?

@scalablecory scalablecory transferred this issue from dotnet/core Jan 13, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Jan 13, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost
Copy link

ghost commented Jan 14, 2021

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Issue Title

FTP Upload Issue After Updating to .Net Core 3.1

General

Version: .Net Core 3.1
OS: Windows
Solution Deployed: Web App Azure
Using Swagger.
Vnet

After Updating the Net Core Version from 2.1 to 3.1 the method to upload a file just stop working after deployed on Azure Web App.

If I Deploy it with a later version (2.1) it starts to work again.

Exception/error

Exception thrown: 'System.Net.WebException' in System.Net.Requests.dll
Unable to connect to remote server

image
image

Code

    public async Task<string> UploadFileFTP(string file)
    {
         FtpConfig ftpConfig = LightConfigurator.Config<FtpConfig>("FtpConfig");           

        FileInfo fileInfo = new FileInfo(file);
        Uri serverUri = new Uri(ftpConfig.Server + ":" + ftpConfig.Port + ftpConfig.Folder + fileInfo.Name);
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
        request.Method = WebRequestMethods.Ftp.UploadFile;
        request.Credentials = new NetworkCredential(ftpConfig.User, ftpConfig.Password);
        request.Proxy = null;
        request.UseBinary = true;
        request.ContentLength = fileInfo.Length;
        using (FileStream fs = fileInfo.OpenRead())
        {
            byte[] buffer = new byte[2048];
            int bytesSent = 0;
            int bytes = 0;
            using (Stream stream = request.GetRequestStream())
            {
                while (bytesSent < fileInfo.Length)
                {
                    bytes = fs.Read(buffer, 0, buffer.Length);
                    stream.Write(buffer, 0, bytes);
                    bytesSent += bytes;
                }
            }
        }

        RegisterEvents.Register(ActionEnum.FPT_UPLOADING, "UploadFileFTP", $"Concluída a subida no FTP.");

        return "success";
    }
Author: d-daniel-de-sousa
Assignees: -
Labels:

area-System.Net, untriaged

Milestone: -

@wfurt
Copy link
Member

wfurt commented Jan 14, 2021

I think we switched to dual mode sockets in 3.x @scalablecory. This feels like dup of #44686.
I would suggest too try it with the WEBSITE_VNET_SUPPORT_DUAL_STACK_SOCKETS = 1.

@karelz
Copy link
Member

karelz commented Jan 15, 2021

@wfurt the linked bug is regression between 3.1 and 5.0. This report is about regression between 2.1 and 3.1, so it won't be likely the same.

Are you able to minimize the repro (ideally HelloWorld style) such that we can try it ourselves as well?
Is your problem specific to Azure WebApps deploymnet? Or are you able to reproduce it also locally?

@wfurt
Copy link
Member

wfurt commented Jan 15, 2021

this is because HTTP switched to dual mode socket in 5.0. Same happened to TcpClient in 3.0 and that impacted FTP in 3.0 as well. Can you reproduce it outside of VNET @d-daniel-de-sousa?

@karelz
Copy link
Member

karelz commented Jan 21, 2021

Triage: Seems to be Azure Web Apps problem, which should be shortly fixed. Closing.

@karelz karelz closed this as completed Jan 21, 2021
@karelz karelz added this to the 6.0.0 milestone Jan 26, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Feb 25, 2021
@karelz karelz removed the untriaged New issue has not been triaged by the area owner label Oct 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants