Sometimes FTP fails

filezilla
ftp can connect but not transfer
ftp connection timed out
cannot connect to ftp server
can't connect to ftp server on local network
ftp connect connection timed out windows
ftp client
ftp error

My project has to upload and download lot of files from and to Unix server using ftp in my windows aoolication. my code is like this

   ftpRequest = (FtpWebRequest)FtpWebRequest.Create(reviewfilepath);

                    ftpRequest.Credentials = new NetworkCredential(user, pass);                        
                    ftpRequest.UseBinary = true;
                    ftpRequest.UsePassive = true;
                    ftpRequest.KeepAlive = false;
                    ftpRequest.Proxy = null;
                    ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
                     ftpStream = ftpRequest.GetRequestStream();
                     FileStream localFileStream = new FileStream(reviewsourcewordpath, FileMode.OpenOrCreate);
                     byte[] byteBuffer = new byte[bufferSize];
                    int bytesSent1 = localFileStream.Read(byteBuffer, 0, bufferSize);

                    try
                    {
                        while (bytesSent1 != 0)
                        {
                            ftpStream.Write(byteBuffer, 0, bytesSent1);
                            bytesSent1 = localFileStream.Read(byteBuffer, 0, bufferSize);
                        }
                        string path = cls_appvars.Set_App_Path + cls_appvars.Set_Log_dir + "SystemLog.txt";
                        System.IO.File.AppendAllText(path, System.DateTime.Now + "***ftp_documents() in cls_accdet***" + jobid + "_review ----- File uploaded Sucessfully" + Environment.NewLine);
                    }
                    catch (Exception ex) { Console.WriteLine(ex.ToString()); }
                    /* Resource Cleanup */
                    localFileStream.Close();
                    ftpStream.Close();
                    ftpRequest = null;

the issue is few times ftp failes and getting the exception

     System.Net.WebException: The operation has timed out.
 at System.Net.FtpWebRequest.GetRequestStream()

I disabled firewall in client machine, enabled ftp.exe and given full rights for the user, but still am getting the exception.

Thanks,

Suressh

Just increase the FtpWebRequest timeout, for example

ftpRequest.Timeout = 30000 // in milliseconds 

Common FTP errors, Common FTP errors. The most common FTP errors are related to incorrect login details supplied or an issue with the hosting server or the internet service provider. In most cases you will see Could not connect to server, but exact errors will vary depending on the issue. The most common FTP errors are related to incorrect login details supplied or an issue with the hosting server or the internet service provider. In most cases you will see Could not connect to server, but exact errors will vary depending on the issue. "530 Login authentication failed" - The error shows that your FTP hostname, username or password are incorrect.

FTP sometimes fail due to packet drop, some connections limits or other technical reasons, it will happen. If your App relies on that transfer, code some retry logic before returning from that call. Put your request into a loop that returns the content on success or rethrows the exception on the third fail.

FTP Connection Errors, "Passive mode" is especially likely to be the problem if your FTP program PASV in the settings; the checkbox is often labeled "PASV FTP" or something similar. I keep using IE & such to visit the ftp'd pages & even login & logoff the ftp site server at times, but seemingly randomly it will fail, even if I use try catch statement, it seems to keep wanting to fail till i go back to IE & go to a webpage on the server or log back in to the account management through IE.

Add this to your config file of your porject.

<configuration>
    <system.net>
        <connectionManagement>
        <add address="*" maxconnection="100" />
        </connectionManagement>
    </system.net>
</configuration>

SOLVED, -sometimes can upload one single file or 2-3 files, but when it comes to upload in bulk/folder(s) FTP client just freezes and won't upload at all or� Your problem is similar to the bug the built in Windows Explorer FTP (ie: Internet Explorer integrated into Explorer.exe) where after navigating a directory it would "lose" your credentials and repeatedly ask you to login. I've never heard of this behavior when using dotnet, though. – David Anderson Apr 28 '11 at 9:15

FTP error 425 failed to establish connection, on a vsftpd server within CentOS 7 there was an error 425 sometimes. ftp.exe from Windows Legacy (2000, XP, 7) support only active ftp (ports 21,20) ftp.exe� You may have to change the settings for FTP under internet explorer settings, follow the steps to change the settings: Open Internet Explorer >> click Tools>> click Internet Options>> Click on Advanced Tab>> under Browsing, find Use Passive FTP (for Firewall and DSL modem Compatibility) and put a check mark>> click apply >> click OK.

Solved: Video Uploads Via FTP Fail and Start Over, Solved: My uploads via FTP used to work just fine, but for the past few weeks Watching it, sometimes it'll get to 99% complete, then fail; sometimes it's 80%,� The script uses Net::FTP->put to write the files, which can be any number of files, not always the same. This | The UNIX and Linux Forums Help wth Net::FTP in script sometimes fails but wsftp always works

SAM tools / [Samtools-help] samtools view through ftp sometimes fails, Hello, I was very happy to realize that samtools view can read remote files through ftp. I am downloading some reads from aligned bam files from the 1000� Therefore, it has been confirmed that Dell's FTP server falls into a heavy load state due to the concentration of access from many servers, and the response becomes slow during this time. Dell is already aware of this phenomenon and is currently working to increase servers to increase access distribution capabilities.

Comments
  • thanks stephan, i already ping the server for whole day there is no failure, am using retry mechanism the issue with that is it blocks further ftp uploads and downloads.. will check on rest of your suggestions..
  • A good ping does not guarantee a good ftp transfer, I'm afraid you have to pool your transfers or use threads to reduce blocking : /
  • Thanks for you advise stephan, let me try and inform you the result. another point that i want to add is each ftp process is a individual backgroundworker.