“未能打开流:FTP服务器报告550”当使用包装访问Microsoft FTP服务上的文件时 [英] "failed to open stream: FTP server reports 550" when accessing file on Microsoft FTP Service using wrapper

查看:308
本文介绍了“未能打开流:FTP服务器报告550”当使用包装访问Microsoft FTP服务上的文件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP中,您有 ftp和ftps的包装,以允许您可以使用 fopen 在FTP上访问文件。



我想使用包装器将文件下载为流。

我的简化代码

  //例如。 $ url =ftp:// username:password@server.com/directory-with-dash/file.mp3; 
$ url ='ftp://'。 urlencode($ username)。 ':'。 urlencode($密码)。 '@'。 $服务器。 $路径。 '/'。 $文件名;
$ ctx = stream_context_create(array('ftp'=> array('resume_pos'=> 0)));
$ fin = fopen($ url,'r',false,$ ctx);

错误:


警告:fopen( ftp:/ /...@server.com/directory-with-dash/file.mp3 ):无法打开流:FTP服务器报告550 /directory-with-dash/file.mp3:系统找不到路径指定。 in /var/www/ftp.php on line 4


更多信息:







编辑:

我注意到 Microsof t FTP服务在连接到FTP时不会将您置于根文件夹中,而是存放在子文件夹中:



当您使用 wget
lockquote
ftp:// username:password@server.com/username/directory-with-dash/file.mp3 //在Chrome $ b中不可用$ b ftp://用户名:password@server.com/directory-with -dash / file.mp3 //在Chrome中正常工作

我已经在PHP中尝试了这两个url - code,但我仍然得到相同的错误。(我输入错了)

解决方案

由FTP服务器不连接到根( / )而是连接到子文件夹( / username )。



与Chrome和wget不同,PHP中的FTP包装似乎需要完整路径而不是相对路径:

适用于Chrome,wget等:


ftp://用户名: password@server.com/directory-with-dash/file.mp3


对于PHP的FTP包装器:


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



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)

解决方案

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

这篇关于“未能打开流:FTP服务器报告550”当使用包装访问Microsoft FTP服务上的文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆