使用PHP时如何获取FTP错误 [英] How to get the FTP error when using PHP
问题描述
我有一个脚本,登录到远程服务器,并尝试使用PHP重命名文件。
I have a script which logs on to a remote server and tries to rename files, using PHP.
代码目前看起来像PHP的这个例子。 net网站:
The code currently looks something like this example from the php.net website:
if (ftp_rename($conn_id, $old_file, $new_file)) {
echo "successfully renamed $old_file to $new_file\n";
} else {
echo "There was a problem while renaming $old_file to $new_file\n";
}
但是...是什么错误?权限,没有这样的目录,磁盘已满?
but ... what was the error? Permissions, no such directory, disk full?
如何让PHP返回FTP错误?这样的东西:
How can I get PHP to return the FTP error? Something like this:
echo "There was a problem while renaming $old_file to $new_file:
the server says $error_message\n";
推荐答案
在这里查看FTP API:
Looking at the FTP API here:
http:// us。 php.net/manual/en/function.ftp-rename.php
似乎没有什么办法可以得到任何东西,但是真的或假的
There doesn't seem to be any way to get anything but true or false.
但是,您可以使用ftp_raw发送一个原始的RENAME命令,然后解析返回的消息。
However, you could use ftp_raw to send a raw RENAME command, and then parse the returned message.
这篇关于使用PHP时如何获取FTP错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!