Failure to download SFTP on server

I have an FTP solution made in C # for uploading files. Works great in local and QA instances. The FTP connection is secured. The file size for the move is in the range 2 - 3 KB. After the solution is ported to Production Server (Windows Server 2012 R2) below error is thrown.

System.Net.WebException: System error. ---> System.Net.InternalException: System error.
   at System.Net.PooledStream.PrePush(Object expectedOwner)
   at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse)
   at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage)
   at System.Net.FtpWebRequest.SyncRequestCallback(Object obj)
   at System.Net.FtpWebRequest.RequestCallback(Object obj)
   at System.Net.CommandStream.Dispose(Boolean disposing)
   at System.IO.Stream.Close()
   at System.IO.Stream.Dispose()
   at System.Net.ConnectionPool.Destroy(PooledStream pooledStream)
   at System.Net.ConnectionPool.PutConnection(PooledStream pooledStream, Object owningObject, Int32 creationTimeout, Boolean canReuse)
   at System.Net.FtpWebRequest.AttemptedRecovery(Exception e)
   at System.Net.FtpWebRequest.SubmitRequest(Boolean async)
   --- End of inner exception stack trace ---
   at System.Net.FtpWebRequest.GetRequestStream()

      

Code -

try
            {
                Stream ftpStream = null;
                /* Create an FTP Request */
                ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + directory + "/" + fileName);
                Logger.Information(string.Format("THE URI TO UPLOAD THE FILE IS - {0}", ftpRequest.RequestUri));
                ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate CERTIFICATE, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
                /* Log in to the FTP Server with the User Name and Password Provided */
                ftpRequest.Credentials = new NetworkCredential(user, pass);
                /* When in doubt, use these options */
                ftpRequest.UseBinary = true;
                ftpRequest.UsePassive = true;
                ftpRequest.KeepAlive = true;
                ftpRequest.EnableSsl = enableSSL;
                ftpRequest.Proxy = null;
                /* Specify the Type of FTP Request */
                ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
                /* Establish Return Communication with the FTP Server */
                ftpStream = ftpRequest.GetRequestStream();
                /* Open a File Stream to Read the File for Upload */
               // FileStream localFileStream = new FileStream(localFile, FileMode.Create);
                /* Buffer for the Downloaded Data */
                byte[] byteBuffer = new byte[bufferSize];

                int bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
                /* Upload the File by Sending the Buffered Data Until the Transfer is Complete */

                    while (bytesSent != 0)
                    {
                        ftpStream.Write(byteBuffer, 0, bytesSent);
                        bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
                    }

                /* Resource Cleanup */
                localFileStream.Close();
                ftpStream.Close();
                ftpRequest = null;
            }
            catch (Exception ex)
            {
                uploadSuccess = false;
                Logger.Error(string.Format("ERROE WHILE UPLOADING FILE {0} TO FTP", fileName), ex);
                Logger.Error(string.Format("EXCEPTION - {0}", ex.ToString()));
            }

      

I tried the following solutions. 1. Allowed ports 21, 22, 898, 990 for Outbound in Firewall 2. Increased FTPWebRequest timeout to 100 minutes. 3. Set proxy as NULL

None of them helped me. Any suggestions?

+3


source to share


1 answer


I have a solution. The production servers were behind a different firewall that was not under my control or access. This was the layer before production servers. I worked with a hosting provider and they made protocol level changes to allow FTP connections. Now the files started uploading to the FTP directory without any problem.



Thanks to everyone who helped me.

+3


source







All Articles