FTP creationTimout error while transfering large files over FTP - c#

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.

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:
Best method to close a keep-alive FTP or FTPS connection in C# (.NET 4.6)?
C# - FtpWebRequest - Multiple requests over the same connection/login

Related

VSTO Outlook Plugin - HttpClient.PostAsync fails without fiddler

I unfortunately had Fiddler running for the whole time I was developing this feature in the plugin and since deploying to clients I found that it will not work for anyone - unless they run fiddler as well! It also does not work on my development machine if I stop running Fiddler.
The main error is Error while copying content to a stream.. So I investigated the possibility of the data I'm POSTing being released by the GC before it finished hitting the server (That, to me, explained why running Fiddler solved it - as I believe the request gets sent to Fiddler first, and then Fiddler sends it to the server). However I couldn't find anything to support that this might be the problem. I have tried making sure it holds onto the data but I don't feel like I'm going down the right route.
The code is roughly like this:
HttpClientHandler httpHandler = new HttpClientHandler { UseDefaultCredentials = true };
var client = new HttpClient(httpHandler, false);
client.BaseAddress = new Uri(BaseUrl + "api/job/PostTest");
var content = new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(System.Globalization.CultureInfo.InvariantCulture));
content.Add(new StringContent(mailItem.HTMLBody, Encoding.UTF8), "BodyHtml");
// content.Add()'s... Omitted for brevity
var response = client.PostAsync(BaseUrl + "api/job/PostTest", content);
response.ContinueWith(prevTask => {
if (prevTask.Result.IsSuccessStatusCode)
{
System.Diagnostics.Debug.WriteLine("Was success");
}
else
{
System.Diagnostics.Debug.WriteLine("Was Error");
}
}, System.Threading.Tasks.TaskContinuationOptions.OnlyOnRanToCompletion);
response.ContinueWith(prevTask =>{
MessageBox.Show(prevTask.Exception.ToString());
}, System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted);
The full exception details are:
System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: Error while copying content to a stream. ---> System.IO.IOException: The read operation failed, see inner exception. ---> System.Net.WebException: The request was aborted: The request was canceled.
at System.Net.ConnectStream.BeginRead(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
at System.Net.Http.HttpClientHandler.WebExceptionWrapperStream.BeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state)
--- End of inner exception stack trace ---
at System.Net.Http.HttpClientHandler.WebExceptionWrapperStream.BeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state)
at System.Net.Http.StreamToStreamCopy.StartRead()
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
---> (Inner Exception #0) System.Net.Http.HttpRequestException: Error while copying content to a stream. ---> System.IO.IOException: The read operation failed, see inner exception. ---> System.Net.WebException: The request was aborted: The request was canceled.
at System.Net.ConnectStream.BeginRead(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
at System.Net.Http.HttpClientHandler.WebExceptionWrapperStream.BeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state)
--- End of inner exception stack trace ---
at System.Net.Http.HttpClientHandler.WebExceptionWrapperStream.BeginRead(Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback, Object state)
at System.Net.Http.StreamToStreamCopy.StartRead()
--- End of inner exception stack trace ---<---
If anyone could point me to some resources that help me or point out where I'm going wrong that would help a lot!
When developing our IronBox Outlook plugin we ran into this issue. What we found was that within the VSTO context, the ServicePointManager supported security protocols was only Tls and Ssl3 (which was not going to work with our API which supported only TLS 1.2 or better).
You can check this easily from within your VSTO code like this (here's an example from when we hooked into Application.ItemSend event):
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// Handle event when item is sent
this.Application.ItemSend += Application_ItemSend;
}
private void Application_ItemSend(object Item, ref bool Cancel)
{
foreach (var c in (SecurityProtocolType[])Enum.GetValues(typeof(SecurityProtocolType)))
{
if (ServicePointManager.SecurityProtocol.HasFlag(c))
{
Debug.WriteLine(c.ToString());
}
}
Cancel = false;
}
We solved it by setting the ServicePointManager.SecurityProtocol property to support Tls12 like this:
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
Hope this helps someone someday,
Kevin
After much searching and much messing about I've not been able to solve this problem using HttpClient so instead what I've done is using WebClient. In case someone else has this problem in the future I'm posting what I ended up using:
System.Net.WebClient wc = new System.Net.WebClient();
wc.Headers.Add("Content-Type", String.Format("multipart/form-data; boundary=\"{0}\"", multipartFormBoundary));
wc.UseDefaultCredentials = true;
try
{
var wcResponse = wc.UploadData(BaseUrl + "api/job/PostJobEmailNote", byteArray);
}
catch(Exception e)
{
// response status code was not in 200's
}
I think problem may be with using anonymous function that returns void. They're a little bit problematic. Changing my lambda to one that returns bools fixed the issue for me.

Attempting to upload to FTP: System.Net.WebException: System error

I have an API that takes in XML and ultimately uploads files based on information in the XML. The uploads are on a schedule (also from XML), and I have tested everything surrounding it and know it works.
I am getting an error about 40% of the time on the first file that I attempt to upload in each time cycle (time cycle = 45 minutes for some files, 30 minutes for others).
Here is my code for the upload:
try {
LoggerFTP.Log("Uploading file: " + filename, false);
// Create the request.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(appSettingsFTP.ftpUrl + #"/" + filename);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Timeout = 6000000; //set to 100 minutes
//request.Timeout = -1; //set to infinite
// Add the login credentials.
request.Credentials = new NetworkCredential(appSettingsFTP.ftpLogin, appSettingsFTP.ftpPassword);
// Grab the file contents.
StreamReader sourceStream = new StreamReader(appSettingsFTP.uploadFileDirectory + filename);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
// Copy the file contents to the outgoing stream.
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
//Logger.Log(filename.ToString() + " " + "Upload Complete, Status: " + response.StatusCode + " " + response.StatusDescription, false);
//Took response.StatusDescription out because it appears to be creating extra line feeds.
LoggerFTP.Log(filename.ToString() + " " + "Upload Complete, Status: " + response.StatusCode, false);
}
catch (Exception ex) {
LoggerFTP.Log(ex.ToString(), false);
}
I have researched the issue and saw something online about it potentially being a speed thing. Like, there is a timeout. But I have my timeout set to 100 minutes for my FtpWebRequest, so it can't possibly be that? I don't know. This is also running as a service so it is hard to test this aspect of the code.
Here is the exception that is getting logged in my logger (e.ToString):
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()
at CPMainSpringAPIExportsSC.UploadFTP.FTPUploadMethod(String viewname, String filename)
I am getting exactly the same stack trace in an SSIS package attempting to FTP over SSL. It works great without SSL, but as soon as I enable SSL, it blows up.
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.IO.Stream.Close() 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.CheckError() at
System.Net.FtpWebRequest.GetRequestStream() at
ST_0ff7348de65a468bb358ab0206e3721f.ScriptMain.Main() in c:\Users\Stephens\AppData\Local\Temp\Vsta\e664c8a71bb647ff9e9dc6ac32d7b615\ScriptMain.cs:line 155 at
System.Net.FtpWebRequest.CheckError() at
System.Net.FtpWebRequest.GetRequestStream() at
ST_0ff7348de65a468bb358ab0206e3721f.ScriptMain.Main() in c:\Users\Stephens\AppData\Local\Temp\Vsta\e664c8a71bb647ff9e9dc6ac32d7b615\ScriptMain.cs:line 155
Because the error is so generic, I decided to look at the .NET source to see if I can catch a clue about what is breaking. If you go here:
http://labs.developerfusion.co.uk/SourceViewer/browse.aspx?assembly=SSCLI&namespace=System.Net#{%22pageClientState%22%3A%22type-2844%2Ccsharp%22}
and skip down to line 281, you will see the definition for internal void PrePush(object expectedOwner) which is what is executing when the exception happens. Here is what it looks like:
internal void PrePush(object expectedOwner)
{
lock (this) {
//3 // The following tests are retail assertions of things we can't allow to happen.
if (null == expectedOwner) {
if (null != m_Owner && null != m_Owner.Target)
throw new InternalException();
// new unpooled object has an owner
}
else {
if (null == m_Owner || m_Owner.Target != expectedOwner)
throw new InternalException();
// unpooled object has incorrect owner
}
m_PooledCount++;
if (1 != m_PooledCount)
throw new InternalException();
// pushing object onto stack a second time
if (null != m_Owner)
m_Owner.Target = null;
}
}
Eventually I discovered that FtpWebRequest only supports explicit FTP (port 21) and not implicit FTP (port 990). This was definitively stated here:
Does .NET FtpWebRequest Support both Implicit (FTPS) and explicit (FTPES)?
Anyway, in my case, it was a firewall issue. Originally we configured for implicit FTP, which was ports 989, 990, 49152-65535 (per the vendor's tech staff). I checked with my network guy and we opened up ports 20, 21, 989, 990 and 40000-655535 for explicit and things worked like a champ afterwards.
However, in your case, you appear to have some connection pool excitement going on. There is a good post on this subject here:
How to improve the Performance of FtpWebRequest?
You might want to take a look at mucking around with your connection pool set up and see if you can make some progress. Hope this helps!
Regards,
Stuart
I know this is an old topic, but for anyone with the same problem, the code that is missing is:
request.EnableSsl = false;

Exception of type 'System.OutOfMemoryException' was thrown in a SFTP connection

Scenario: a i have an app that makes connection with a SFTP server and download a file. The code that do this:
while (true)
{
try
{
var connectionInfo = // creating a new connection info of a Renci.SshNet lib
var client = new SftpClient(connectionInfo);
client.Connect();
using (SftpFileStream sftpFileStream = client.OpenRead(path)
{
using (FileStream fileStream = new FileStream(filePath, FileMode.CreateNew))
{
int BUFFER_SIZE = 2048;
byte[] buffer = new byte[BUFFER_SIZE];
int readBytes = sftpFileStream.Read(buffer, 0, BUFFER_SIZE);
while (readBytes > 0)
{
fileStream.Write(buffer, 0, readBytes);
readBytes = sftpFileStream.Read(buffer, 0, BUFFER_SIZE);
}
}
}
client.Dispose();
}
catch (Exception e)
{
log.Error(e);
}
Thread.Sleep(1 hour);
}
In the line client.Connect() a first error was raised:
Renci.SshNet.Common.SftpPathNotFoundException: No such file at Renci.SshNet.Sftp.SubsystemSession.WaitHandle(WaitHandle waitHandle, TimeSpan operationTimeout) at Renci.SshNet.Sftp.SftpSession.RequestOpen(String path, Flags flags, Boolean nullOnError) at Renci.SshNet.Sftp.SftpFileStream..ctor(SftpSession session, String path, FileMode mode, FileAccess access, Int32 bufferSize, Boolean useAsync) at Renci.SshNet.Sftp.SftpFileStream..ctor(SftpSession session, String path, FileMode mode, FileAccess access) at Renci.SshNet.SftpClient.OpenRead(String path) at Infraero.TINE3.STTColetor.Negocio.Drivers.DriverAbstratoArquivoFTP.BaixarArquivoPABXSFTP(ConfiguracaoColetor configuracaoColetor, String arquivoPABX) in D:\SVN\STT\trunk\3-0_CodigoFonte_Coletor\3-4_SRC\Infraero.TINE3.STTColetor.Negocio\Drivers\DriverAbstratoArquivoFTP.cs:line 446 at Infraero.TINE3.STTColetor.Negocio.Drivers.DriverAbstratoArquivoFTP.ProcessarArquivoSFTP(SftpFile arquivo, ConfiguracaoColetor configuracaoColetor, List'1 listaBilhetes) in D:\SVN\STT\trunk\3-0_CodigoFonte_Coletor\3-4_SRC\Infraero.TINE3.STTColetor.Negocio\Drivers\DriverAbstratoArquivoFTP.cs:line 658 at Infraero.TINE3.STTColetor.Negocio.Drivers.DriverAbstratoArquivoFTP.ColetarBilhetes(ConfiguracaoColetor configuracaoColetor, List'1 listaBilhetes, String ultimoArquivoTransmitido) in D:\SVN\STT\trunk\3-0_CodigoFonte_Coletor\3-4_SRC\Infraero.TINE3.STTColetor.Negocio\Drivers\DriverAbstratoArquivoFTP.cs:line 73 at Infraero.TINE3.STTColetor.Negocio.Coletor.ColetarBilhetes() in D:\SVN\STT\trunk\3-0_CodigoFonte_Coletor\3-4_SRC\Infraero.TINE3.STTColetor.Negocio\Coletor.cs:line 56 at Infraero.TINE3.STTColetor.WindowsService.ServicoColetor..ctor() in D:\SVN\STT\trunk\3-0_CodigoFonte_Coletor\3-4_SRC\Infraero.TINE3.STTColetor.WindowsService\ServicoColetor.cs:line 85
After 1 hour the process try download the file again, but raises a new error in line client.Connect():
System.Threading.Tasks.TaskSchedulerException: An exception was thrown by a TaskScheduler. ---> System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at System.Threading.Thread.StartInternal(IPrincipal principal, StackCrawlMark& stackMark) at System.Threading.Thread.Start(StackCrawlMark& stackMark) at System.Threading.Thread.Start(Object parameter) at System.Threading.Tasks.ThreadPoolTaskScheduler.QueueTask(Task task) at System.Threading.Tasks.Task.ScheduleAndStart(Boolean needsProtection) --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ScheduleAndStart(Boolean needsProtection) at System.Threading.Tasks.Task.InternalStartNew(Task creatingTask, Object action, Object state, CancellationToken cancellationToken, TaskScheduler scheduler, TaskCreationOptions options, InternalTaskOptions internalOptions, StackCrawlMark& stackMark) at System.Threading.Tasks.TaskFactory.StartNew(Action action, TaskCreationOptions creationOptions) at Renci.SshNet.Session.ExecuteThread(Action action) at Renci.SshNet.Session.Connect() at Renci.SshNet.BaseClient.Connect() at Infraero.TINE3.STTColetor.Negocio.Drivers.DriverAbstratoArquivoFTP.ConectarServidorSFTP(String servidor, Int32 porta, String login, String senha) in D:\SVN\STT\trunk\3-0_CodigoFonte_Coletor\3-4_SRC\Infraero.TINE3.STTColetor.Negocio\Drivers\DriverAbstratoArquivoFTP.cs:line 551 at Infraero.TINE3.STTColetor.Negocio.Drivers.DriverAbstratoArquivoFTP.RequisitarArquivoServidorSFTP(ConfiguracaoColetor configuracaoColetor) in D:\SVN\STT\trunk\3-0_CodigoFonte_Coletor\3-4_SRC\Infraero.TINE3.STTColetor.Negocio\Drivers\DriverAbstratoArquivoFTP.cs:line 519 at Infraero.TINE3.STTColetor.Negocio.Drivers.DriverAbstratoArquivoFTP.ColetarBilhetes(ConfiguracaoColetor configuracaoColetor, List'1 listaBilhetes, String ultimoArquivoTransmitido) in D:\SVN\STT\trunk\3-0_CodigoFonte_Coletor\3-4_SRC\Infraero.TINE3.STTColetor.Negocio\Drivers\DriverAbstratoArquivoFTP.cs:line 67 at Infraero.TINE3.STTColetor.Negocio.Coletor.ColetarBilhetes() in D:\SVN\STT\trunk\3-0_CodigoFonte_Coletor\3-4_SRC\Infraero.TINE3.STTColetor.Negocio\Coletor.cs:line 56 at Infraero.TINE3.STTColetor.WindowsService.ServicoColetor..ctor() in D:\SVN\STT\trunk\3-0_CodigoFonte_Coletor\3-4_SRC\Infraero.TINE3.STTColetor.WindowsService\ServicoColetor.cs:line 85
After 1 day, the second error continues, and the memory usage of the app increased from 60MB to 800MB.
Anyone knows what the problem can be?
A quick glance through the code base of the library that you're using (http://sshnet.codeplex.com/SourceControl/changeset/view/18974) shows that SftpClient also implements IDisposable, but you're not cleaning it up or closing it when something fails. You should try something like:
try
{
var connectionInfo = // something
using(var client = new SftpClient(connectionInfo))
{
client.Connect();
using(var sftpFileStream = client.OpenRead(path))
{
// download the file
}
}
}
It may also be a memory leak inside the library that you're using.

C# FTP ListDirectoryDetails Problem

I try to read file list from FTP from direcotry that contains over 1000 files.
I do it like this :
public static FtpWebRequest GetRequest(string uri)
{
FtpWebRequest req = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
req.Credentials = new NetworkCredential("login", "password");
req.KeepAlive = false;
req.UseBinary = false;
req.UsePassive = true;
return req;
}
public static bool CheckConnection()
{
FtpWebResponse respSize = null;
try
{
FtpWebRequest reqFTP = GetRequest(#"ftp://myftp.com");
reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
respSize = (FtpWebResponse)reqFTP.GetResponse();
respSize.Close();
respSize = null;
reqFTP.GetResponse().Close();
return true;
}
catch (Exception ex)
{
//...
}
finally
{
if (respSize != null)
respSize.Close();
}
return false;
}
I get an error:
The remote server returned an error:
(451) Local error in processing.
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.FinishRequestStage(RequestStage
stage)
at
System.Net.FtpWebRequest.SyncRequestCallback(Object
obj)
at
System.Net.FtpWebRequest.RequestCallback(Object
obj)
at
System.Net.CommandStream.Abort(Exception
e)
at
System.Net.CommandStream.CheckContinuePipeline()
at
System.Net.FtpWebRequest.DataStreamClosed(CloseExState
closeState)
at
System.Net.FtpDataStream.System.Net.ICloseEx.CloseEx(CloseExState
closeState)
at
System.Net.FtpDataStream.Dispose(Boolean
disposing)
at System.IO.Stream.Close()
at
System.Net.FtpWebResponse.Close()
at CheckConnection()
does anyone knows what is going on ?
regards
Marcin
From RhinoSoft (makers of the FTP software Serv-U):
"A 451 reply code may be sent in response to any command initiating a file transfer. It is a transient negative response, which means the error condition is a temporary one. It is usually sent in response to the server encountering an unexpected local error when processing data it is transferring or receiving. In this case, the client is encouraged to restart the FTP transaction and try again." [1]
So, it may be an issue with communication between your software and the FTP server, not necessarily an issue with your software itself.
It can't hurt to increase the length of the Timeout property of FtpWebRequest, but that's not likely to be the cause based on my research.

An established connection was aborted by the software in your host machine

Sorry if this is a bit long winded but I thought better to post more than less.
This is also my First post here, so please forgive.
I have been trying to figure this one out for some time. and to no avail, hoping there is a genius out there who has encountered this before.
This is an intermittent problem and has been hard to reproduce.
The code that I am running simply calls a web service
The Web Service call is in a loop (so we could be doing this a lot, 1500 times or more)
Here is the code that is causing the error:
HttpWebRequest groupRequest = null;
WebResponse groupResponse = null;
try
{
XmlDocument doc = new XmlDocument();
groupRequest = (HttpWebRequest)HttpWebRequest.Create(String.Format(Server.HtmlDecode(Util.GetConfigValue("ImpersonatedSearch.GroupLookupUrl")),userIntranetID));
groupRequest.Proxy = null;
groupRequest.KeepAlive = false;
groupResponse = groupRequest.GetResponse();
doc.Load(groupResponse.GetResponseStream());
foreach (XmlElement nameElement in doc.GetElementsByTagName(XML_GROUP_NAME))
{
foreach (string domain in _groupDomains )
{
try
{
string group = new System.Security.Principal.NTAccount(domain, nameElement.InnerText).Translate(typeof(System.Security.Principal.SecurityIdentifier)).Value;
impersonationChain.Append(";").Append(group);
break;
}
catch{}
} // loop through
}
}
catch (Exception groupLookupException)
{
throw new ApplicationException(String.Format(#"Impersonated Search ERROR: Could not find groups for user<{0}\{1}>", userNTDomain, userIntranetID), groupLookupException);
}
finally
{
if ( groupResponse != null )
{
groupResponse.Close();
}
}
Here is the error that happens sometimes:
Could not find groups for user<DOMAIN\auser> ---> System.IO.IOException: Unable to read
data from the transport connection: An established connection was aborted by the
software in your host machine. ---> System.Net.Sockets.SocketException: An established
connection was aborted by the software in your host machine at
System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags
socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32
size) --- End of inner exception stack trace --- at System.Net.ConnectStream.Read(Byte[]
buffer, Int32 offset, Int32 size) at System.Xml.XmlTextReaderImpl.ReadData() at
System.Xml.XmlTextReaderImpl.ParseDocumentContent() at
System.Xml.XmlLoader.LoadDocSequence
(XmlDocument parentDoc) at System.Xml.XmlDocument.Load(XmlReader reader) at
System.Xml.XmlDocument.Load(Stream inStream) at
MyWebServices.ImpersonatedSearch.PerformQuery(QueryParameters parameters,
String userIntranetID, String userNTDomain)--- End of inner exception stack trace
---at MyWebServices.ImpersonatedSearch.PerformQuery(QueryParameters parameters, String userIntranetID, String userNTDomain)
--- End of inner exception stack trace ---
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message,
WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName,
Object[] parameters) at MyProgram. MyWebServices.ImpersonatedSearch.PerformQuery
(QueryParameters parameters, String userIntranetID, String userNTDomain)
at MyProgram.MyMethod()
Sorry that was alot of code to read through.
This happens about 30 times out of around 1700
You're probably hitting a timeout. First of all, turn the keepalive back on. Second, check the timestamps on the request and reply. If there is a firewall between the sender and receiver, make sure that it isn't closing the connection because of idle timeout. I've had both these problems in the past, although with generic socket programming, not DB stuff.

Categories

Resources