Tech Off Thread

3 posts

FTP Port

Back to Forum: Tech Off
  • User profile image
    Ion Todirel

    Hey guys,

    i have a problem with FTP Classes in .NET Framework 2.0 BCL.

    This code will work if FTP server is set with default port 21, but if is not, then... will not work:

    FtpWebRequest request = WebRequest.Create(Uri) as FtpWebRequest;

    request
    .Credentials = new
    NetworkCredential("John Todirel", "home");
    request
    .Method = WebRequestMethods.Ftp.
    RemoveDirectory;

    FtpWebResponse response = request.GetResponse() as FtpWebResponse;
    MessageBox.Show(response.
    StatusDescription);

    response.Close();

    so how to change FTP Port? any ideas?

  • User profile image
    Maurits

    If the port is 2121, change the URI to be ftp://ftp.example.com:2121/dir/file.ext

  • User profile image
    Ion Todirel

    Maurits wrote:
    If the port is 2121, change the URI to be ftp://ftp.example.com:2121/dir/file.ext


    i use this:

    string uri = "ftp://127.0.0.1/";
    UriBuilder newUriPort = new UriBuilder(uri);
    newUriPort.Port = 20;
    uri = newUriPort.Uri.ToString(); // ftp://127.0.0.1:20/

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.