Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 66401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:05:51+00:00 2026-05-10T19:05:51+00:00

I’m trying to get the following code working: string url = String.Format(@SOMEURL); string user

  • 0

I’m trying to get the following code working:

  string url = String.Format(@'SOMEURL');   string user = 'SOMEUSER';   string password = 'SOMEPASSWORD';    FtpWebRequest ftpclientRequest = (FtpWebRequest)WebRequest.Create(new Uri(url));   ftpclientRequest.Method = WebRequestMethods.Ftp.ListDirectory;   ftpclientRequest.UsePassive = true;    ftpclientRequest.Proxy = null;   ftpclientRequest.Credentials = new NetworkCredential(user, password);   FtpWebResponse response = ftpclientRequest.GetResponse() as FtpWebResponse; 

This normally works, but for 1 particular server this gives an Error 500: Syntax not recognized. The Change Directory command is disabled on the problem server, and the site administrator told me that .NET issues a Change Directory command by default with all FTP connections. Is that true? Is there a way to disable that?
EDIT: When I login from a command line I am in the correct directory:
ftp> pwd
257 ‘/’ is current directory

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:05:51+00:00Added an answer on May 10, 2026 at 7:05 pm

    I just tested this on one of our dev servers and indeed there is a CWD issued by the .NET FtpWebRequest:

     new connection from 172.16.3.210 on 172.16.3.210:21 (Explicit SSL) hostname resolved : devpc sending welcome message. 220 Gene6 FTP Server v3.10.0 (Build 2) ready... USER testuser testuser, 331 Password required for testuser. testuser, PASS **** testuser, logged in as 'testuser'. testuser, 230 User testuser logged in. testuser, OPTS utf8 on testuser, 501 Please CLNT first. testuser, PWD testuser, 257 '/' is current directory. testuser, CWD / testuser, change directory '/' -> 'D:\testfolder' --> Access allowed. testuser, 250 CWD command successful. '/' is current directory. testuser, TYPE I testuser, 200 Type set to I. testuser, PORT 172,16,3,210,4,127 testuser, 200 Port command successful. testuser, NLST testuser, 150 Opening data connection for directory list. testuser, 226 Transfer ok. testuser, 421 Connection closed, timed out. testuser, disconnected. (00d00:05:01) 

    This was without even specifying ‘/’ in the uri when creating the FtpWebRequest object.

    If you debug or browse the source code, a class called ‘FtpControlStream’ comes into play. See call stack:

     System.dll!System.Net.FtpControlStream.BuildCommandsList(System.Net.WebRequest req) Line 555    C# System.dll!System.Net.CommandStream.SubmitRequest(System.Net.WebRequest request =      {System.Net.FtpWebRequest}, bool async = false, bool readInitalResponseOnConnect = true) Line 143   C# System.dll!System.Net.FtpWebRequest.TimedSubmitRequestHelper(bool async) Line 1122 + 0x13 bytes C# System.dll!System.Net.FtpWebRequest.SubmitRequest(bool async = false) Line 1042 + 0xc bytes C# System.dll!System.Net.FtpWebRequest.GetResponse() Line 649  C# 

    There’s a method named BuildCommandsList() which is invoked. BuildCommandsList() builds a list of commands to send to the FTP server. This method has the following snippet of code:

    if (m_PreviousServerPath != newServerPath) {      if (!m_IsRootPath         && m_LoginState == FtpLoginState.LoggedIn         && m_LoginDirectory != null)     {          newServerPath = m_LoginDirectory+newServerPath;     }      m_NewServerPath = newServerPath;       commandList.Add(new PipelineEntry(FormatFtpCommand('CWD', newServerPath), PipelineEntryFlags.UserCommand));  } 

    Upon the first connection to the server m_PreviousServerPath is always null, the value of newServerPath is ‘/’ and is computed by a function named GetPathAndFileName() (invoked a few lines prior to this block of code). GetPathAndFileName() computes newServerPath as ‘/’ if no path is supplied or if ‘/’ is explicitly tacked on the end of the ‘ftp://….’ uri.

    So this of course ultimately causes the CWD command to be added to the command pipeline because null != ‘/’.

    In a nutshell unfortunately you can’t override this behaviour because it’s burned in the source.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 109k
  • Answers 109k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should avoid writing complex business login in the view.… May 11, 2026 at 9:24 pm
  • Editorial Team
    Editorial Team added an answer It turns out the error was an internal error of… May 11, 2026 at 9:24 pm
  • Editorial Team
    Editorial Team added an answer It seems that you need to set the checked attribute… May 11, 2026 at 9:24 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.