[Mono-bugs] [Bug 477611] New: WebClient.DownloadData throws exception on FTP GET download
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Thu Feb 19 05:52:16 EST 2009
https://bugzilla.novell.com/show_bug.cgi?id=477611
Summary: WebClient.DownloadData throws exception on FTP GET
download
Classification: Mono
Product: Mono: Class Libraries
Version: SVN
Platform: 32bit
OS/Version: Ubuntu
Status: NEW
Severity: Normal
Priority: P5 - None
Component: System
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: martijndijksterhuis at gmail.com
QAContact: mono-bugs at lists.ximian.com
Found By: ---
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.6)
Gecko/2009020911 Ubuntu/8.10 (intrepid) Firefox/3.0.6
When downloading an FTP file through WebClient the attached program throws a
method not supported exception on Mono (CVS). The program runs fine on Visual
C# Studio.
The problem is caused by line 274 in Webclient.CS it assigns "GET" as the way
to retrieve the file through FTP. (Which should be sane way to download an FTP
file)
274: request = SetupRequest (address, "GET");
A few lines further the code in FTPWebRequest.cs (line 226) checks for "GET" in
"supportedCommands", cannot find it and throws the exception.
226: if (value.Length == 0 || Array.BinarySearch (supportedCommands, value) <
0)
227: throw new ArgumentException ("Method not supported", "value");
Reproducible: Always
Steps to Reproduce:
1.Use the attached code to download a file through FTP
2.Watch it crash
Actual Results:
System.Net.WebException
Expected Results:
Programs returns the FTP file in a byte[]
// Main.cs created with MonoDevelop
// User: martijn at 4:39 PM 2/18/2009
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//
using System;
using System.Net;
namespace BasicFTPClientNamespace
{
class BasicFTPClient
{
public string Username;
public string Password;
public string Host;
public int Port;
public BasicFTPClient()
{
Username = "anonymous";
Password = "anonymous at internet.com";
Port = 21;
Host = "";
}
public BasicFTPClient(string theUser,string thePassword,string
theHost)
{
Username = theUser;
Password = thePassword;
Host = theHost;
Port = 21;
}
private Uri BuildServerUri(string Path)
{
return new Uri(String.Format("ftp://{0}:{1}/{2}",Host,Port,Path));
}
public byte[] DownloadData(string path)
{
byte [] FileData = null;
// Get the object used to communicate with the server.
WebClient request = new WebClient();
// Logon to the server using username + password
request.Credentials = new NetworkCredential (Username,Password);
try
{
Uri URL = BuildServerUri(path);
FileData = request.DownloadData (BuildServerUri(path));
}
catch (WebException e)
{
Console.WriteLine(e.ToString());
}
return FileData;
}
}
class MainClass
{
public static void Main(string[] args)
{
BasicFTPClient MyClient = new BasicFTPClient();
MyClient.Host="myserver";
MyClient.Port=21;
MyClient.Username="username";
MyClient.Password="password";
byte[] Data = MyClient.DownloadData("mytest.txt");
}
}
}
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the mono-bugs
mailing list