doujilou3903 2014-01-10 11:10
浏览 76
已采纳

使用包装器访问Microsoft FTP服务上的文件时“无法打开流:FTP服务器报告550”

In PHP, you have wrappers for ftp and ftps to allow you access files on an FTP using fopen.

I want to use the wrapper to download a file as a stream.

My simplified 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' => array('resume_pos' => 0)));
$fin = fopen($url, 'r', false, $ctx);

Error:

Warning: fopen(ftp://...@server.com/directory-with-dash/file.mp3): 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

More Info:

  • The same url works fine when used with wget on the same machine.
  • Using PHP's FTP extension to download files works fine
  • FTP server responds with 220 Microsoft FTP Service and 215 Windows_NT
  • FTP server can handle passive mode
  • Using filesize($url); results in Warning: filesize(): stat failed for...
  • allow_url_fopen setting is On
  • The same code worked fine against a different FTP-server, 215 UNIX Type: L8

What might be causing the problem?

Edit:

I have noticed that the Microsoft FTP Service doesn't place you in the root folder when you connect to the FTP, but in a subfolder:

/username

This subfolder must not be in the URL when you use wget or a web browser:

ftp://username:password@server.com/username/directory-with-dash/file.mp3 // Not available in Chrome ftp://username:password@server.com/directory-with-dash/file.mp3 // Works fine in Chrome

I have tried both urls in the PHP-code, but I get the same error still. (I typed it wrong)

  • 写回答

1条回答 默认 最新

  • dongquanyu5816 2014-01-10 12:38
    关注

    The problem was caused by the FTP server not connecting to root (/) but rather to a subfolder (/username).

    Unlike Chrome and wget, the FTP wrapper in PHP seems to require to have the full path and not the relative path:

    For Chrome, wget, etc.:

    ftp://username:password@server.com/directory-with-dash/file.mp3

    For PHP's FTP wrapper:

    ftp://username:password@server.com/username/directory-with-dash/file.mp3

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?