![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | FTP Connection Closed Error I have written a Windows service that periodically lists the contents of an FTP directory until a new file becomes available. Then, it gets the new file and writes it to the local server. Most of the time, this works fine, but occasionally I get the following exception while getting the directory listing: Message: The underlying connection was closed: An unexpected error occurred on a receive. Source: System, Void SyncRequestCallback(System.Object) Inner Exception: Stack Trace: at System.Net.FtpWebRequest.SyncRequestCallback(Object obj) at System.Net.FtpWebRequest.RequestCallback(Object obj) at System.Net.CommandStream.Abort(Exception e) at System.Net.FtpWebRequest.FinishRequestStage(RequestStage stage) at System.Net.FtpWebRequest.GetResponse() at RiverFlowBackup.FileTransfer.ListFiles() at RiverFlowBackup.FileTransfer.GetNameOfLastestFile() at RiverFlowBackup.FileTransfer.WaitForNewFile() at RiverFlowBackup.RFBService.timerExecute_Elapsed(Object sender, ElapsedEventArgs e) I'm beginning to think that when I get this error, the request for the directory list is taking longer than usual and some timeout period of around 15 seconds is causing the connection to close. I have the KeepAlive property of the FTP object set to FALSE and the TimeOut property is set to 3 minutes (180000ms). Below is the relevent code: private ArrayList ListFiles() { ArrayList fileNames = new ArrayList(); // Build the FTP request to get the directory listing FtpWebRequest request = BuildRequest(WebRequestMethods.Ftp.ListDirectory); // Execute the request and get the response from the FTP server FtpWebResponse response = null; Stream responseStream = null; StreamReader reader = null; try { // Get the response from the FTP server response = (FtpWebResponse)request.GetResponse(); // Access the contents of the response responseStream = response.GetResponseStream(); reader = new StreamReader(responseStream); // Read each line of the response contents. Each line contains one file name. while (!reader.EndOfStream) { string fileName = reader.ReadLine(); // Verify that the file name matches the format defined in the application // configuration settings. If it does, add it to the file name array that // is returned by this function. Regex ex = new Regex(ftpFileFilter); if (ex.IsMatch(fileName)) fileNames.Add(fileName); } } finally { // Release resources if (reader != null) reader.Close(); if (responseStream != null) responseStream.Close(); if (response != null) response.Close(); } return fileNames; } private FtpWebRequest BuildRequest(string method) { return this.BuildRequest(method, String.Empty); } private FtpWebRequest BuildRequest(string method, string fileName) { // Build the FTP request object string filePath = ftpPath + fileName; FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(filePath); request.Method = method; request.Credentials = new NetworkCredential(ftpUserName, ftpPassword); request.Timeout = ftpTimeout; request.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache); request.KeepAlive = false; request.UseBinary = (ftpTransferType == TransferTypeEnum.Binary); request.Proxy = null; return request; } Thank you in advance for your help. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| !HELP! - I made a science Report and when I closed it and reopend it ERROR!!! | Vista file management | |||
| VB.NET application cliick-once deployment via internet - Error - Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. | .NET General | |||
| ERROR!!! "Spooler Subsystem App Stopped Working And Was Closed" | Vista print fax & scan | |||
| Loses Wireless Connection when Laptop Lid is Closed | Vista General | |||