Problem with WebRequestMethods.Ftp.UploadFile;

I am very new to .NET and I'm trying to create an FTP tool. I found the following code on the Microsoft site. For some reason I'm getting the following error when I try and compile the code:

"The type or namespace name 'WebRequestMethods' could not be found (are you missing a using directive or an assembly reference )"

It doesn't like the line:
request.Method = WebRequestMethods.Ftp.UploadFile;

From what I understand the using directive "
using System;" should be sufficent;

Any feedback on this problem would be greatly appreciated.


using System;
using System.IO;
using System.Net;
using System.Text;

namespace Examples.System.Net
{
public class WebRequestGetExample
{
public static void Main ()
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://mytargetsite.com");
request.Method = WebRequestMethods.Ftp.UploadFile;

// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential ("username","password");

// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader("C:\\Inetpub\\wwwroot\\cloaking\\files2trans\\ideas.txt");
byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;

Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();

FtpWebResponse response = (FtpWebResponse)request.GetResponse();

Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

response.Close();
}
}
}



Answer this question

Problem with WebRequestMethods.Ftp.UploadFile;

  • Rahul Virli

    I think the problem is that I'm running an older version of .NET. Thanks a lot for responding.

  • Andrew SES

    It compiled perfectly for me.
    Are you sure you are using .NET 2.0 compiler


  • Problem with WebRequestMethods.Ftp.UploadFile;