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);
}
}
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);
}
}