1

I'm transferring an updated program to the client through FTP server. The folder has a total size of 250 MB, I'm facing this problem.

"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()\r\n 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.GetResponse() at WMSUpdateManager.FTPManagerClass.getFileSizeOfDir(String filename) in C:\Users\USER\source\repos\WMSUpdateManager\WMSUpdateManager\FTPManagerClass.cs:line 472 at WMSUpdateManager.FTPManagerClass.getFileSize(String filename) in C:\Users\USER\source\repos\WMSUpdateManager\WMSUpdateManager\FTPManagerClass.cs:line 439 at WMSUpdateManager.FTPManagerClass.DownloadFileSet(String remoteFile, String localFile) in C:\Users\USER\source\repos\WMSUpdateManager\WMSUpdateManager\FTPManagerClass.cs:line 118"

I'm also using this block in a recursive function to get the directory size.

FtpWebRequest sizeRequest;

sizeRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + filename);
sizeRequest.Credentials = new NetworkCredential(username, password);
sizeRequest.UsePassive = true;
sizeRequest.KeepAlive = true;
sizeRequest.Method = WebRequestMethods.Ftp.GetFileSize;
sizeRequest.UseBinary = true;
sizeRequest.EnableSsl = false;
sizeRequest.Timeout = -1;
FtpWebResponse respSize = (FtpWebResponse)sizeRequest.GetResponse();   //problem at line 472 
size = respSize.ContentLength;
sizeRequest = null;
respSize.Close();

My log file.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
H DA
  • 53
  • 8
  • Show us [log file](https://stackoverflow.com/q/9664650/850848). – Martin Prikryl Jun 29 '18 at 15:18
  • How large a file are you sending? <10M,10M+, 20M+ – jdweng Jun 29 '18 at 15:30
  • @jdweng the file is 250 MB – H DA Jun 29 '18 at 19:09
  • Does the server limit the size of the transfer? 250MB sound like server may be dropping connection. I would use sniffer and check TCP transport layer for a FIN. – jdweng Jun 29 '18 at 19:35
  • @jdweng no I transferred the file using the filezella client successfully. this code is called within the download operation.within that function I'm not even using this call recursively. the download checks if it's a directory or a file then if file it downloads or if it's a directory it lists the files and calls itself for each one. the exception was catched in the downloading function. – H DA Jun 30 '18 at 06:29
  • @MartinPrikryl I have attached the log file – H DA Jun 30 '18 at 06:29

1 Answers1

0

This looks like the culprit:

System.Net Information: 0 : [7640] FtpControlStream#54444047 - Received response [421 No-transfer-time exceeded. Closing control connection.]

Your FTP server closes your connection after some time, if you do not do any file transfer. "Size" requests likely do not count as "transfers".


What you can do is to force FtpWebRequest to open new connection, before the server closes the current one.

For example, this will make .NET open new connection every minute:

sizeRequest.ConnectionGroupName = DateTime.Now.ToString("yyyy-MM-dd-HH-mm");

See also:

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992