Downloading file from Unix not working

P

Parrot

I am trying to download a file from a Unix server to my Windows platform and
the file is not being downloaded. My code is shown below:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpsite);
request.AuthenticationLevel = System.Net.Security.AuthenticationLevel.None;
request.Credentials = new NetworkCredential(UserID, UserPassword);
request.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Message.Text = response.StatusDescription;
response.Close();

The variable ftpsite is set to an ftp address such as
"ftp://ftp.myserver/myfile.dat"

When in debug mode I get the response " 125 Data connection already open -
transfer starting".

Do I have to do some kind of timing operation to keep examining the response
to see if I get a download complete message before I close the response? It
appears that if I go right on through the process without stopping, the
download will not finish. Can anyone see any errors in my coding?
 
P

Parrot

I have answered my own question after some research. If anyone wants to know
how to download a file from an ftp server to the PC here is the amended code:

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpsite);
request.AuthenticationLevel = System.Net.Security.AuthenticationLevel.None;
request.Credentials = new NetworkCredential(UserID, UserPassword);
request.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
string record = "";
StreamWriter wr = new StreamWriter(fileName);
while (reader.Peek() > 0)
{
record = reader.ReadLine();
wr.Write(record);
}
reader.Close();
wr.Close();
Message.Text = response.StatusDescription;
response.Close();
 

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