using @ symbol with ftp stream in DirectoryIterator
I'm using DirectoryIterator class to list ftp content: $a = new DirectoryIterator('ftp://user:password@host');
If there is an at "@" character in login, i get an error: failed to op开发者_运维百科en dir: operation failed
How i can escape @ symbol in login?
I try: %40, + \@
RFC1738 mandates the special characters like @
should be urlencoded in the ftp:// scheme. So using %40
in place of the @ in a password fragement would be correct.
But you just wanted the user:password@
prefix before the hostname. Those don't need escaping. And it's already natively supported by the ftp fopen url wrapper:
$d = opendir("ftp://anonymous:nopwd@ftp.kernel.org/pub/");
print readdir($d);
Above ftp:// url works for me with DirectoryIterator
too, but gives some obscure warning and different results. So I would test with the native functions first.
I am not that sure you can use DirectoryIterator
as FTP
client
You may want to learn how to use ftp_rawlist to get a list of the given directory
精彩评论