.NET Framework Bookmark and Share   
 index > Network Class Library (System.Net) > ftpwebrequest/ftpwebresponse :The underlying connection was closed: An unexpected error occurred on a receive and the remote name could not be resolved
 

ftpwebrequest/ftpwebresponse :The underlying connection was closed: An unexpected error occurred on a receive and the remote name could not be resolved

Hi

I am downloading bunch of files from FTP Server via Iridium Modem. I am getting the following exceptions in between of downloading files.
System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.
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.IO.Stream.Dispose()
at ContentServer.CDownloadManager.download_from_server(String source, String usrName, String passWord, String destPath) in G:\Tests\Content_Server\Content_Server\DownloadManager.cs:line 177 8/27/2009 3:17:29 PM
MLS_TeamSchedules.zip Failed 8/27/2009 3:17:29 PM
System.Net.WebException: The remote name could not be resolved: 'ftp.yellowbrix.com'
at System.Net.FtpWebRequest.GetResponse()
at ContentServer.CDownloadManager.download_from_server(String source, String usrName, String passWord, String destPath) in G:\Tests\Content_Server\Content_Server\DownloadManager.cs:line 159 8/27/2009 3:18:54 PM
MLS_TeamScores.zip Failed 8/27/2009 3:18:54 PM


The trace log for the above:

System.Net Verbose: 0 : [2756] WebRequest::Create(ftp://ftp.yellowbrix.com/data/MLS_TeamSchedules.zip)
System.Net Information: 0 : [2756] FtpWebRequest#13350567::.ctor(ftp://ftp.yellowbrix.com/data/MLS_TeamSchedules.zip)
System.Net Verbose: 0 : [2756] Exiting WebRequest::Create() -> FtpWebRequest#13350567
System.Net Verbose: 0 : [2756] FtpWebRequest#13350567::GetResponse()
System.Net Information: 0 : [2756] FtpWebRequest#13350567::GetResponse(Method=RETR.)
System.Net Information: 0 : [2756] Associating FtpWebRequest#13350567 with FtpControlStream#64109423
System.Net Information: 0 : [2756] FtpControlStream#64109423 - Sending command [TYPE I]
System.Net.Sockets Verbose: 0 : [2756] Socket#31364015::Send()
System.Net.Sockets Verbose: 0 : [2756] Data from Socket#31364015::Send
System.Net.Sockets Verbose: 0 : [2756] 00000000 : 54 59 50 45 20 49 0D 0A- : TYPE I..
System.Net.Sockets Verbose: 0 : [2756] Exiting Socket#31364015::Send() -> 8#8
System.Net.Sockets Verbose: 0 : [2756] Socket#31364015::Receive()
System.Net.Sockets Verbose: 0 : [2756] Data from Socket#31364015::Receive
System.Net.Sockets Verbose: 0 : [2756] 00000000 : 32 30 30 20 53 77 69 74-63 68 69 6E 67 20 74 6F : 200 Switching to
System.Net.Sockets Verbose: 0 : [2756] 00000010 : 20 42 69 6E 61 72 79 20-6D 6F 64 65 2E 0D 0A : Binary mode...
System.Net.Sockets Verbose: 0 : [2756] Exiting Socket#31364015::Receive() -> 31#31
System.Net Information: 0 : [2756] FtpControlStream#64109423 - Received response [200 Switching to Binary mode.]
System.Net Information: 0 : [2756] FtpControlStream#64109423 - Sending command [PASV]
System.Net.Sockets Verbose: 0 : [2756] Socket#31364015::Send()
System.Net.Sockets Verbose: 0 : [2756] Data from Socket#31364015::Send
System.Net.Sockets Verbose: 0 : [2756] 00000000 : 50 41 53 56 0D 0A : PASV..
System.Net.Sockets Verbose: 0 : [2756] Exiting Socket#31364015::Send() -> 6#6
System.Net.Sockets Verbose: 0 : [2756] Socket#31364015::Receive()
System.Net.Sockets Verbose: 0 : [2756] Data from Socket#31364015::Receive
System.Net.Sockets Verbose: 0 : [2756] 00000000 : 32 32 37 20 45 6E 74 65-72 69 6E 67 20 50 61 73 : 227 Entering Pas
System.Net.Sockets Verbose: 0 : [2756] 00000010 : 73 69 76 65 20 4D 6F 64-65 20 28 32 30 35 2C 31 : sive Mode (205,1
System.Net.Sockets Verbose: 0 : [2756] 00000020 : 39 36 2C 38 32 2C 31 31-2C 32 32 30 2C 35 35 29 : 96,82,11,220,55)
System.Net.Sockets Verbose: 0 : [2756] 00000030 : 0D 0A : ..
System.Net.Sockets Verbose: 0 : [2756] Exiting Socket#31364015::Receive() -> 50#50
System.Net Information: 0 : [2756] FtpControlStream#64109423 - Received response [227 Entering Passive Mode (205,196,82,11,220,55)]
System.Net.Sockets Verbose: 0 : [2756] Socket#37915543::Socket(InterNetwork#2)
System.Net.Sockets Verbose: 0 : [2756] Exiting Socket#37915543::Socket()
System.Net.Sockets Verbose: 0 : [2756] Socket#37915543::Connect(11:56375#189929722)
System.Net.Sockets Verbose: 0 : [2756] Exiting Socket#37915543::Connect()
System.Net Information: 0 : [2756] FtpControlStream#64109423 - Sending command [RETR MLS_TeamSchedules.zip]
System.Net.Sockets Verbose: 0 : [2756] Socket#31364015::Send()
System.Net.Sockets Verbose: 0 : [2756] Data from Socket#31364015::Send
System.Net.Sockets Verbose: 0 : [2756] 00000000 : 52 45 54 52 20 4D 4C 53-5F 54 65 61 6D 53 63 68 : RETR MLS_TeamSch
System.Net.Sockets Verbose: 0 : [2756] 00000010 : 65 64 75 6C 65 73 2E 7A-69 70 0D 0A : edules.zip..
System.Net.Sockets Verbose: 0 : [2756] Exiting Socket#31364015::Send() -> 28#28
System.Net.Sockets Verbose: 0 : [2756] Socket#31364015::Receive()
System.Net.Sockets Verbose: 0 : [2756] Data from Socket#31364015::Receive
System.Net.Sockets Verbose: 0 : [2756] 00000000 : 31 35 30 20 4F 70 65 6E-69 6E 67 20 42 49 4E 41 : 150 Opening BINA
System.Net.Sockets Verbose: 0 : [2756] 00000010 : 52 59 20 6D 6F 64 65 20-64 61 74 61 20 63 6F 6E : RY mode data con
System.Net.Sockets Verbose: 0 : [2756] 00000020 : 6E 65 63 74 69 6F 6E 20-66 6F 72 20 4D 4C 53 5F : nection for MLS_
System.Net.Sockets Verbose: 0 : [2756] 00000030 : 54 65 61 6D 53 63 68 65-64 75 6C 65 73 2E 7A 69 : TeamSchedules.zi
System.Net.Sockets Verbose: 0 : [2756] 00000040 : 70 20 28 33 39 30 20 62-79 74 65 73 29 2E 0D 0A : p (390 bytes)...
System.Net.Sockets Verbose: 0 : [2756] Exiting Socket#31364015::Receive() -> 80#80
System.Net Information: 0 : [2756] FtpControlStream#64109423 - Received response [150 Opening BINARY mode data connection for MLS_TeamSchedules.zip (390 bytes).]
System.Net Verbose: 0 : [2756] Exiting FtpWebRequest#13350567::GetResponse()
System.Net.Sockets Verbose: 0 : [2756] Socket#37915543::Receive()
System.Net.Sockets Error: 0 : [2756] Exception in the Socket#37915543::Receive - An existing connection was forcibly closed by the remote host
System.Net.Sockets Verbose: 0 : [2756] Exiting Socket#37915543::Receive() -> 0#0
System.Net.Sockets Verbose: 0 : [2756] Socket#37915543::Dispose()
System.Net.Sockets Verbose: 0 : [2756] Socket#31364015::Receive()
System.Net.Sockets Error: 0 : [2756] Exception in the Socket#31364015::Receive - An existing connection was forcibly closed by the remote host
System.Net.Sockets Verbose: 0 : [2756] Exiting Socket#31364015::Receive() -> 0#0
System.Net.Sockets Verbose: 0 : [2756] Socket#31364015::Dispose()
System.Net Information: 0 : [2756] FtpWebRequest#13350567::(Releasing FTP connection#64109423.)
System.Net Verbose: 0 : [2756] FtpWebResponse#43253384::Close()
System.Net Verbose: 0 : [2756] Exiting FtpWebResponse#43253384::Close()
System.Net Verbose: 0 : [2756] WebRequest::Create(ftp://ftp.yellowbrix.com/data/MLS_TeamScores.zip)
System.Net Information: 0 : [2756] FtpWebRequest#18075529::.ctor(ftp://ftp.yellowbrix.com/data/MLS_TeamScores.zip)
System.Net Verbose: 0 : [2756] Exiting WebRequest::Create() -> FtpWebRequest#18075529
System.Net Verbose: 0 : [2756] FtpWebRequest#18075529::GetResponse()
System.Net Information: 0 : [2756] FtpWebRequest#18075529::GetResponse(Method=RETR.)
System.Net Warning: 0 : [2756] ScriptEngine was notified of a change in the IP configuration and will update WebProxy settings.
System.Net Warning: 0 : [2756] WebProxy failed to autodetect a Uri for a proxy script.
System.Net Warning: 0 : [2756] WebProxy failed to autodetect a Uri for a proxy script.
System.Net.Sockets Verbose: 0 : [2756] Socket#59621546::Socket(InterNetwork#2)
System.Net.Sockets Verbose: 0 : [2756] Exiting Socket#59621546::Socket()
System.Net.Sockets Verbose: 0 : [2756] Socket#21353980::Socket(InterNetworkV6#23)
System.Net.Sockets Verbose: 0 : [2756] Exiting Socket#21353980::Socket()
System.Net.Sockets Verbose: 0 : [2756] Exiting DNS::InternalResolveFast()
System.Net.Sockets Verbose: 0 : [2756] Socket#59621546::Dispose()
System.Net.Sockets Verbose: 0 : [2756] Socket#21353980::Dispose()
System.Net Error: 0 : [2756] Exception in the FtpWebRequest#18075529::GetResponse - The remote name could not be resolved: 'ftp.yellowbrix.com'
System.Net Error: 0 : [2756] at System.Net.FtpWebRequest.GetResponse()
System.Net Verbose: 0 : [2756] Exiting FtpWebRequest#18075529::GetResponse()


My code:

FtpWebRequest

reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);
//Set request to download a file in binary mode
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary =
true;
reqFTP.UsePassive =
true;
reqFTP.Credentials = ContentManager.Ftp_Credential;
//open request and get response stream

using (FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse())

{

using (Stream ftpStream = response.GetResponseStream())

{

//loop to read & write to file

using (FileStream outputStream = new FileStream(destPath, FileMode.Create))

{

int bufferSize = 2048;

int readCount;

byte[] buffer = new byte[bufferSize];

readCount = ftpStream.Read(buffer, 0, bufferSize);

while (readCount > 0)

{

outputStream.Write(buffer, 0, readCount);

readCount = ftpStream.Read(buffer, 0, bufferSize);

}

}

}

}

Any help is highly appreciated.
Regards
Raju

  •  
Siravuri
The lines on the trace that you highlighted on bold indicate that the connection with the server has been lost (is your modem connection reliable while running your app?).Also a change is happening in your machine connection configuration forcing System.Net to rediscover the proxy to use with your application. This operation is failling as well as the subsequent resolution for the name of your ftp server.

If you don't go through a proxy server, you should uncheck the "Automatically Detect Settings" option in theLAN Settings dialog of the Connections tab inInternet Explorer.System.Net uses this settings to determine if it has to use a proxy or not.

Please let me know if this addresses your issue

Thanks

Reymarx Gereda [MSFT]
Reymarx Gereda

You can use google to search for other answers

Custom Search

More Threads

• Need help retrieving a udp response after sending a udp command
• RequestCacheLevel
• Problem using ServicePoint->BindIPEndPointDelegate
• SMTP mail server with CRAM / DIGEST MD5 auth
• NegotiateStream delegation problem
• HttpWebRequest - SOCKS4 or SOCKS5 support?
• FtpWebRequest - multi-threading issues
• Download all swf files from web page
• how can i simulate a web xml upload in c# windows application?
• How to access mailbox inbox with use of CDO?