title: How can I use FTP to move files between directories?
body: <p>I have a program that needs to move a file from one directory to another on an FTP server.  For example, the file is in:</p>
  
  <pre><code>ftp://1.1.1.1/MAIN/Dir1
  </code></pre>
  
  <p>and I need to move the file to:</p>
  
  <pre><code>ftp://1.1.1.1/MAIN/Dir2
  </code></pre>
  
  <p>I found a couple of articles recommending use of the Rename command, so I tried the following:</p>
  
  <pre><code>    Uri serverFile = new Uri(“ftp://1.1.1.1/MAIN/Dir1/MyFile.txt");
      FtpWebRequest reqFTP= (FtpWebRequest)FtpWebRequest.Create(serverFile);
      reqFTP.Method = WebRequestMethods.Ftp.Rename;
      reqFTP.UseBinary = true;
      reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPass);
      reqFTP.RenameTo = “ftp://1.1.1.1/MAIN/Dir2/MyFile.txt";
  
      FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
  </code></pre>
  
  <p>But this doesn’t seem to work – I get the following error:</p>
  
  <blockquote>
    <p>The remote server returned an error: (550) File unavailable (e.g., file not found, no access).</p>
  </blockquote>
  
  <p>At first I thought this might relate to permissions, but as far as I can see, I have permissions to the entire FTP site (it is on my local PC and the uri is resolved to localhost).</p>
  
  <p>Should it be possible to move files between directories like this, and if not, how is it possible?</p>
  
  <p>To address some of the point / suggestions that have been raised:</p>
  
  <ol>
  <li>I can download the same file from the source directory, so it definitely exists (what I'm doing is downloading the file first, and then moving it somewhere else).</li>
  <li>I can access the ftp site from a browser (both the source and target directory)</li>
  <li>The ftp server is running under my own IIS instance on my local machine.</li>
  <li>The path and case are correct and there are no special characters.</li>
  </ol>
  
  <p>Additionally, I have tried setting the directory path to be:</p>
  
  <pre><code>ftp://1.1.1.1/%2fMAIN/Dir1/MyFile.txt
  </code></pre>
  
  <p>Both for the source and target path - but this makes no difference either.</p>
  
  <p>I found <a href="http://naveedhanif.wordpress.com/2010/05/17/ftpwebrequest-renameto-directory/" rel="noreferrer">this</a> article, which seems to say that  specifying the destination as a relative path would help - it doesn't appear to be possible to specify an absolute path as the destination.</p>
  
  <pre><code>reqFTP.RenameTo = “../Dir2/MyFile.txt";
  </code></pre>