Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

donload a logfile from a server using ftpwebrequest

Status
Not open for further replies.

MackAA

Programmer
Mar 21, 2006
13
CA
Hello everybody,

I'm facing a weird problem in my asp.net 2.0 website using the ftpwebrequest class. I want to donwdload the logfile from an ftpserver and I get the following error:
"the remote server returned an error: (530) Not Logged In"

this is my code:

protected void btnTestLF_Click(object sender, EventArgs e) {
Uri ur = new Uri("ftp://ftp.mydomaine.com/");
Downloadlf(ur, "myname", "mypwd");
}



private string Downloadlf(Uri serverUri, string name, string pwd) {

// The serverUri parameter should start with the ftp:// scheme.
if (serverUri.Scheme != Uri.UriSchemeFtp) {
return string.Empty;
}
// Get the object used to communicate with the server.
WebClient request = new WebClient();
request.Credentials = new NetworkCredential(name, pwd, serverUri.AbsoluteUri);

try {//the next line is the problem:

byte[] newFileData = request.DownloadData(serverUri.ToString());

/*I tried also the following:
byte[] newFileData = request.DownloadData(serverUri.DnsSafeHost);
byte[] newFileData = request.DownloadData(serverUri.AbsoluteUri);
byte[] newFileData = request.DownloadData(serverUri.AbsolutePath);
the problem still the same
*/
string fileString = System.Text.Encoding.UTF8.GetString(newFileData);

}
catch (WebException e){
//call the ErrorManagement class to store the error in the database

}
return string.Empty;
}


Could anyone give me some help! I'll appreciate it very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top