ftpWebResponse fails on alternate calls

J

Jeremy

I'm getting a list of files from an ftp site using the following method. On
the first call this works perfectly. On the 2nd call, it fails with the
following error. On the 3rd call it succeeds again.

"Failed to list incoming files from ftp site The remote server returned an
error: (550) File unavailable (e.g., file not found, no access)."

I'm guessing that the ftp server thinks the ftpUserID is already connected,
but I don't see any way to disconnect. Any suggestions?

- Jeremy

internal void listFiles(List<string> incomingFiles)
{
FtpWebRequest request =
(FtpWebRequest)WebRequest.Create(ftpPath);
request.UsePassive = false;
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential(ftpUserID,
ftpPassword);
try
{
FtpWebResponse response =
(FtpWebResponse)request.GetResponse(); <== FAILS HERE.
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);

incomingFiles.Clear();
string file = reader.ReadLine();
while (file != null)
{
incomingFiles.Add(file);
file = reader.ReadLine();
}
reader.Close();
responseStream.Close();//jhg 06/16/2008
response.Close(); //jhg 06/16/2008
}
catch (Exception ex)
{
onProgressEventArgs args = new onProgressEventArgs("Failed
to list incoming files from ftp site " + ex.Message);
showProgress(this, args);
}
}
 
P

parez

I'm getting a list of files from an ftp site using the following method. On
the first call this works perfectly. On the 2nd call, it fails with the
following error. On the 3rd call it succeeds again.

"Failed to list incoming files from ftp site The remote server returned an
error: (550) File unavailable (e.g., file not found, no access)."

I'm guessing that the ftp server thinks the ftpUserID is already connected,
but I don't see any way to disconnect. Any suggestions?

- Jeremy

internal void listFiles(List<string> incomingFiles)
{
FtpWebRequest request =
(FtpWebRequest)WebRequest.Create(ftpPath);
request.UsePassive = false;
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential(ftpUserID,
ftpPassword);
try
{
FtpWebResponse response =
(FtpWebResponse)request.GetResponse(); <== FAILS HERE.
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);

incomingFiles.Clear();
string file = reader.ReadLine();
while (file != null)
{
incomingFiles.Add(file);
file = reader.ReadLine();
}
reader.Close();
responseStream.Close();//jhg 06/16/2008
response.Close(); //jhg 06/16/2008
}
catch (Exception ex)
{
onProgressEventArgs args = new onProgressEventArgs("Failed
to list incoming files from ftp site " + ex.Message);
showProgress(this, args);
}
}

is the ftp server load balanced? alternate calls succeed could mean
load balancing issue.. where one server does not have the file.
you could use a regular ftp client and connect to the server and see
what happens try it couple of times in a row.

just a thought..
 
J

Jeremy

parez said:
is the ftp server load balanced? alternate calls succeed could mean
load balancing issue.. where one server does not have the file.
you could use a regular ftp client and connect to the server and see
what happens try it couple of times in a row.

Not load balanced. FileZilla connects consecutively, although it asks
"break current connection?" each time. Interesting suggestion though.

Jeremy
 

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