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< stringincomingF iles)
{
FtpWebRequest request =
(FtpWebRequest) WebRequest.Crea te(ftpPath);
request.UsePass ive = false;
request.Method = WebRequestMetho ds.Ftp.ListDire ctory;
request.Credent ials = new NetworkCredenti al(ftpUserID,
ftpPassword);
try
{
FtpWebResponse response =
(FtpWebResponse )request.GetRes ponse(); <== FAILS HERE.
Stream responseStream = response.GetRes ponseStream();
StreamReader reader = new StreamReader(re sponseStream);
incomingFiles.C lear();
string file = reader.ReadLine ();
while (file != null)
{
incomingFiles.A dd(file);
file = reader.ReadLine ();
}
reader.Close();
responseStream. Close();//jhg 06/16/2008
response.Close( ); //jhg 06/16/2008
}
catch (Exception ex)
{
onProgressEvent Args args = new onProgressEvent Args("Failed
to list incoming files from ftp site " + ex.Message);
showProgress(th is, args);
}
}
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< stringincomingF iles)
{
FtpWebRequest request =
(FtpWebRequest) WebRequest.Crea te(ftpPath);
request.UsePass ive = false;
request.Method = WebRequestMetho ds.Ftp.ListDire ctory;
request.Credent ials = new NetworkCredenti al(ftpUserID,
ftpPassword);
try
{
FtpWebResponse response =
(FtpWebResponse )request.GetRes ponse(); <== FAILS HERE.
Stream responseStream = response.GetRes ponseStream();
StreamReader reader = new StreamReader(re sponseStream);
incomingFiles.C lear();
string file = reader.ReadLine ();
while (file != null)
{
incomingFiles.A dd(file);
file = reader.ReadLine ();
}
reader.Close();
responseStream. Close();//jhg 06/16/2008
response.Close( ); //jhg 06/16/2008
}
catch (Exception ex)
{
onProgressEvent Args args = new onProgressEvent Args("Failed
to list incoming files from ftp site " + ex.Message);
showProgress(th is, args);
}
}
Comment