FtpWebRequest: ListDirectoryDetails with "Unable to connect to theremote server"

P

Patrick.Simons

I try to connect a FTPWebRequest through Proxy and VPN to a remote
FTP- server. Sometimes it works sometimes not. When my VB.Net-App
(2005) returns the error on the GetResponse-Method, I'll try to use
the Windows Explorer to go on the FTP-URI and this always works. So
the problem should come from my app.

my simplified code:

Private m_oFTP As FtpWebRequest
Private oResponseDir As FtpWebResponse = Nothing

m_oFTP = FtpWebRequest.Create("ftp://" & m_sFTPIP & "//" &
m_sNetTraDir & "/*.TRA") With m_oFTP
.Credentials = New NetworkCredential(m_sFTPUsr, m_sFTPPwd)
.UseBinary = True
.KeepAlive = True
.Method = WebRequestMethods.Ftp.ListDirectoryDetails
Try
oResponseDir = .GetResponse()
bRc = True
Catch ex As Exception
....
End With

The trace file shows this:

System.Net Verbose: 0 : [3956] WebRequest::Create(ftp://10.70.5.19//
EXPORT/FTP_E02/*.TRA)
System.Net Information: 0 : [3956]
FtpWebRequest#64923656::.ctor(ftp://
10.70.5.19//EXPORT/FTP_E02/*.TRA)
System.Net Verbose: 0 : [3956] Exiting WebRequest::Create() ->
FtpWebRequest#64923656
System.Net Verbose: 0 : [3956] FtpWebRequest#64923656::GetResponse()
System.Net Information: 0 : [3956]
FtpWebRequest#64923656::GetResponse(Method=LIST.)
System.Net Warning: 0 : [3956] WebProxy failed to autodetect a Uri for
a proxy script.
System.Net Warning: 0 : [3956] WebProxy failed to autodetect a Uri for
a proxy script.
System.Net Error: 0 : [3956] Exception in the
FtpWebRequest#64923656::GetResponse - Unable to connect to the remote
server
System.Net Error: 0 : [3956] at
System.Net.FtpWebRequest.GetResponse()
System.Net Verbose: 0 : [3956] Exiting
FtpWebRequest#64923656::GetResponse()


Any ideas...
 
K

kimiraikkonen

I try to connect a FTPWebRequest through Proxy and VPN to a remote
FTP- server. Sometimes it works sometimes not. When my VB.Net-App
(2005) returns the error on the GetResponse-Method, I'll try to use
the Windows Explorer to go on the FTP-URI and this always works. So
the problem should come from my app.

my simplified code:

Private m_oFTP As FtpWebRequest
Private oResponseDir As FtpWebResponse = Nothing

m_oFTP = FtpWebRequest.Create("ftp://" & m_sFTPIP & "//" &
m_sNetTraDir & "/*.TRA") With m_oFTP
      .Credentials = New NetworkCredential(m_sFTPUsr, m_sFTPPwd)
      .UseBinary = True
      .KeepAlive = True
      .Method = WebRequestMethods.Ftp.ListDirectoryDetails
      Try
          oResponseDir = .GetResponse()
          bRc = True
      Catch ex As Exception
       ....
End With

The trace file shows this:

System.Net Verbose: 0 : [3956] WebRequest::Create(ftp://10.70.5.19//
EXPORT/FTP_E02/*.TRA)
System.Net Information: 0 : [3956]
FtpWebRequest#64923656::.ctor(ftp://
10.70.5.19//EXPORT/FTP_E02/*.TRA)
System.Net Verbose: 0 : [3956] Exiting WebRequest::Create()     ->
FtpWebRequest#64923656
System.Net Verbose: 0 : [3956] FtpWebRequest#64923656::GetResponse()
System.Net Information: 0 : [3956]
FtpWebRequest#64923656::GetResponse(Method=LIST.)
System.Net Warning: 0 : [3956] WebProxy failed to autodetect a Uri for
a proxy script.
System.Net Warning: 0 : [3956] WebProxy failed to autodetect a Uri for
a proxy script.
System.Net Error: 0 : [3956] Exception in the
FtpWebRequest#64923656::GetResponse - Unable to connect to the remote
server
System.Net Error: 0 : [3956]    at
System.Net.FtpWebRequest.GetResponse()
System.Net Verbose: 0 : [3956] Exiting
FtpWebRequest#64923656::GetResponse()

Any ideas...

Hi,
Just a guess as far as based on your code, it may a trouble because of
your application gets timed out due to absence of Timeout property.
You can try to set a enlarged FtpWebRequest.Timeout property (in
miliseconds) to test it.

http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.timeout.aspx

Hope this helps,

Onur Güzel
 
P

Patrick.Simons

It has nothing to do with the Timeout. When the property isn't set,
the timeout is infinite.

What could be the difference between using FtpWebRequest or using the
windows explorer (XP SP3)?

BTW: I use a VPN-connection....
 
K

kimiraikkonen

It has nothing to do with the Timeout. When the property isn't set,
the timeout is infinite.

What could be the difference between using FtpWebRequest or using the
windows explorer (XP SP3)?

BTW: I use a VPN-connection....

Not sure, MSDN says:

"To specify an infinite value, set the Timeout property to Infinite
(-1). "

Thus, you "may" need to set:
System.Threading.Timeout.Infinite


Worth to try.

Onur Güzel
 
P

Patrick.Simons

Yes indeed, the default value for the Timeout is not infinite, it's
100000 (100 ms).
But changing it to System.Threading.Timeout.Infinite doesn't change my
problem.

Any other thoughts?
 
P

Patrick.Simons

I find a solution. It seems that the FTP-server doesn't always want to
answer the FtpWebRequest.GetResponse(), so I made some
pings in a loop to force the server to answer (in VB.Net with
System.Net.NetworkInformation.Ping). After I got the first positive
reply from the ping, the FtpWebRequest.GetResponse() worked fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top