title: "failed to open stream: FTP server reports 550" when accessing file on Microsoft FTP Service using wrapper
body: <p>In PHP, you have <a href="http://www.php.net/manual/en/wrappers.ftp.php" rel="nofollow">wrappers for ftp and ftps</a> to allow you access files on an FTP using <a href="http://php.net/manual/en/function.fopen.php" rel="nofollow">fopen</a>.</p>
  
  <p>I want to use the wrapper to download a file as a stream.</p>
  
  <p><strong>My simplified code:</strong></p>
  
  <pre><code>// eg. $url = "ftp://username:password@server.com/directory-with-dash/file.mp3";
  $url = 'ftp://' . urlencode($username) . ':' . urlencode($password) . '@' . $server . $path . '/' . $filename;
  $ctx = stream_context_create(array('ftp' =&gt; array('resume_pos' =&gt; 0)));
  $fin = fopen($url, 'r', false, $ctx);
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <blockquote>
    <p>Warning: fopen(<a href="ftp://...@server.com/directory-with-dash/file.mp3" rel="nofollow">ftp://...@server.com/directory-with-dash/file.mp3</a>): failed to open stream: FTP server reports 550 /directory-with-dash/file.mp3: The system cannot find the path specified. in /var/www/ftp.php on line 4</p>
  </blockquote>
  
  <p><strong>More Info:</strong></p>
  
  <ul>
  <li>The same url works fine when used with <a href="http://www.gnu.org/software/wget/" rel="nofollow">wget</a> on the same machine.</li>
  <li>Using PHP's <a href="http://www.php.net/manual/en/ref.ftp.php" rel="nofollow">FTP extension</a> to download files works fine</li>
  <li>FTP server responds with <code>220 Microsoft FTP Service</code> and <code>215 Windows_NT</code></li>
  <li>FTP server can handle passive mode</li>
  <li>Using <code>filesize($url);</code> results in <code>Warning: filesize(): stat failed for...</code></li>
  <li><code>allow_url_fopen</code> setting is <code>On</code></li>
  <li>The same code worked fine against a different FTP-server, <code>215 UNIX Type: L8</code></li>
  </ul>
  
  <p>What might be causing the problem?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I have noticed that the <code>Microsoft FTP Service</code> doesn't place you in the root folder when you connect to the FTP, but in a subfolder:</p>
  
  <blockquote>
    <p>/username</p>
  </blockquote>
  
  <p>This subfolder must not be in the URL when you use <code>wget</code> or a web browser:</p>
  
  <blockquote>
    <p><a href="ftp://username:password@server.com/username/directory-with-dash/file.mp3" rel="nofollow">ftp://username:password@server.com/username/directory-with-dash/file.mp3</a> // Not available in Chrome
    <a href="ftp://username:password@server.com/directory-with-dash/file.mp3" rel="nofollow">ftp://username:password@server.com/directory-with-dash/file.mp3</a> // Works fine in Chrome</p>
  </blockquote>
  
  <p><strike>I have tried both urls in the PHP-code, but I get the same error still.</strike> (I typed it wrong)</p>