title: Problem renaming file on FTP server in .NET Framework 4.0 only!
body: <p>I am having a problem renaming a FTP file using the following code:</p>
  
  <pre><code>    Dim Request As FtpWebRequest = DirectCast(WebRequest.Create(New Uri("ftp://sftp.mycompany.com/myfile.txt")), FtpWebRequest)
      'Set that we will be renaming a file
      Request.Method = WebRequestMethods.Ftp.Rename
      'Provide the new filename
      Request.RenameTo = NewFileName
      'The credentials needed to log onto the server
      Request.Credentials = New NetworkCredential("username", "password")
      'We are going to enable SSL for the communication with the FTP server as required by the remote server.
      Request.EnableSsl = True
      Request.UsePassive = True
      Request.KeepAlive = False
      'Create a Response object getting the downloaded file
      Dim Response As FtpWebResponse = DirectCast(Request.GetResponse(), FtpWebResponse)
      Response.Close()
  </code></pre>
  
  <p>I never actually had it working or needed renaming an FTP file until .NET 4.0 so that was the 1st code I wrote. A close derivitave of this code to download the file WORKS so it is not an SSL or FTP issue (read on for tracing detail) Apparently though this code was documented to work in Framework 3.5 or prior.  In VS.NET 2010 .NET Framework 4.0 project I always get back: "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."</p>
  
  <p>Guess what... copied the exact code into an old VS.NET 2008 test project ran it again -> worked perfectly!</p>
  
  <p>So I thought I would just wrap this code up in a binary targeting the 3.5 Framework and then reference it in my VS.NET 2010 project to outsmart the bug, but it did not work.</p>
  
  <p>I tried adding a workaround I found stating to add the prefix "%2E/" to the filename did not work for me.  My trace log kept outputting the same results:</p>
  
  <p>System.Net Information: 0 : [2228] FtpControlStream#15409429 - Received response [257 "/users/company" is current directory]<br>
  System.Net Information: 0 : [2228] FtpControlStream#15409429 - Sending command <strong>[RNFR /myfile.txt]</strong><br>
  System.Net Information: 0 : [2228] FtpControlStream#15409429 - Received response [550 File /myfile.txt not found]<br></p>
  
  <p>VS.NET 2008 has different results ommiting the 1st slash before the rename file:</p>
  
  <p>System.Net Information: 0 : [6460] FtpControlStream#40715158 - Received response [257 "/users/company" is current directory]<br>
  System.Net Information: 0 : [6460] FtpControlStream#40715158 - Sending command [CWD /users/company/]<br>
  System.Net Information: 0 : [6460] FtpControlStream#40715158 - Received response [250 Command CWD succeed]<br>
  System.Net Information: 0 : [6460] FtpControlStream#40715158 - Sending command <strong>[RNFR myfile.txt]</strong><br>
  System.Net Information: 0 : [6460] FtpControlStream#40715158 - Received response [350 Enter new name]<br>
  System.Net Information: 0 : [6460] FtpControlStream#40715158 - Sending command [RNTO myfileOLD.txt]<br>
  System.Net Information: 0 : [6460] FtpControlStream#40715158 - Received response [250 Renamed]<br></p>
  
  <p>I have tried every combination and can't get this working, except when running in VS.NET 2008 or prior. This does sound like a bug or an undocumented procedure change that probably warrants an entry on connect.microsoft.com.</p>
  
  <p>Any help or suggestions on this?</p>
  
  <p>Thanks!</p>