FTP connection failing with “Unable to connect to the remote server”

Moderator: Project members

Post Reply
Message
Author
nkr_
500 Command not understood
Posts: 4
Joined: 2019-10-15 07:49

FTP connection failing with “Unable to connect to the remote server”

#1 Post by nkr_ » 2019-10-15 07:56

Hello,

I am experiencing some issues in my .NET Core 2.2 setup where I have a feature that needs to process a lot of files located on our VM. To retrieve the files, I make continous ftpwebrequests, with FileZilla as our FTP Server running on the VM.
The issue comes when I need to download hundreds of files using the FTPWebrequests, somewhere random between 300-400 requests, I get the error "Unable to connect to the remote server".

My code for retrieving the files looks like this:

Code: Select all

	    FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(filepath);
            ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
            ftpRequest.Credentials = new NetworkCredential("username", "password");
            
            if (finalProcessRequest)
            {
                ftpRequest.KeepAlive = false;
            }
            else
            {
                ftpRequest.KeepAlive = true;
            }
            
            Encoding encoding = Encoding.GetEncoding(Settings.StandardCodingPage);

            if (useUTF8)
            {
                encoding = Encoding.UTF8;
            }

            if (codePage != -1)
            {
                encoding = Encoding.GetEncoding(codePage);
            }

            StringBuilder objectCode = new StringBuilder();

            FtpWebResponse webResponse = (FtpWebResponse) ftpRequest.GetResponse();
            Stream responseStream = webResponse.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream, encoding);

            string line;
            while ((line = await reader.ReadLineAsync()) != null)
            {
                objectCode.AppendLine(line);
            }

            reader.Close();
            webResponse.Close();

            result = objectCode.ToString();

User avatar
botg
Site Admin
Posts: 35491
Joined: 2004-02-23 20:49
First name: Tim
Last name: Kosse

Re: FTP connection failing with “Unable to connect to the remote server”

#2 Post by botg » 2019-10-15 11:09

Do you still experience this issue after switching to a non-garbage-collected language?

nkr_
500 Command not understood
Posts: 4
Joined: 2019-10-15 07:49

Re: FTP connection failing with “Unable to connect to the remote server”

#3 Post by nkr_ » 2019-10-15 11:55

Hi botg,

I don't know if it would work in a non-garbage-collected language, and I need it to work for this setup. There's no indicator to what is causing it, it just happens randomly in the request range of 300 to 400, I never get past that amount of requests (Total download requests I need to make is 1300 ish), the files themselves aren't more than 20 to 350 KB in size.

Please help.

Thanks,
Nikolaj.

nkr_
500 Command not understood
Posts: 4
Joined: 2019-10-15 07:49

Re: FTP connection failing with “Unable to connect to the remote server”

#4 Post by nkr_ » 2019-10-18 09:02

I tried different approaches and looked for optimal settings to set in the FileZilla Server, but I haven't been able to get past the issue yet and could really use some help.

nkr_
500 Command not understood
Posts: 4
Joined: 2019-10-15 07:49

Re: FTP connection failing with “Unable to connect to the remote server”

#5 Post by nkr_ » 2019-10-18 12:34

Update:

I have modified the code to run the file processing in parallel, instead of a normal loop.
Besides making it run in parallel, I added try/catch with a sleep timer and repeat cycle on catches - this takes care of most of the processes hitting "unable to connect to remote".

Further more, I increased the number of threads and buffer sizes in my FileZilla Server, took some time adjusting and testing to find what worked best for my setup, but overall, everything is getting smooth now and out of roughly 2100 file download requests over ftp, only 2-3 (random) are hitting "unable to connect to remote" error.

User avatar
boco
Contributor
Posts: 26899
Joined: 2006-05-01 03:28
Location: Germany

Re: FTP connection failing with “Unable to connect to the remote server”

#6 Post by boco » 2019-10-18 21:41

The occasional error messages are normal for FTP due to its nature of using many ports instead of only one. There's always the change of occasionally hitting a socket that cannot serve the request at that very moment. FileZilla is meant to mitigate these issues, it will simply retry and the server will use a different socket that hopefully works, then.
### BEGIN SIGNATURE BLOCK ###
No support requests per PM! You will NOT get any reply!!!
FTP connection problems? Please do yourself a favor and read Network Configuration.
FileZilla connection test: https://filezilla-project.org/conntest.php
### END SIGNATURE BLOCK ###

BarryMB
500 Command not understood
Posts: 1
Joined: 2020-02-11 14:30

Re: FTP connection failing with “Unable to connect to the remote server”

#7 Post by BarryMB » 2020-02-11 14:35

Dear All,
Could some one help me to fix this pbm.
Since this morning, I have the same error.
Thx for any help

Post Reply