download logfile from an ftp server using ftpwebrequest
-
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!Just Relax And Keep It Simple.
-
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!Just Relax And Keep It Simple.
Here is a good example of FTP Download: http://www.codeproject.com/cs/internet/SimpleFTPDemo.asp[^]
Pete Soheil DigiOz Multimedia http://www.digioz.com