Search code examples
phpftpwrapperxboxftp-server

What's the FTP command sent by FTP wrapper on PHP


I'm developing a very simple system in PHP that basically list all my xbox's screenshots as thumbnails. The xbox connected to my LAN and I'm doin this using PHP to connect to the Xbox's FTP server and list the wanted files, and that's working fine.

The problem is that when I use the function file_get_contents("ftp://user:pass@ftp_ip/path/screenshots/image.bmp") the ftp server send me the response "500 command unrecognized".

No matter what command I use to open the file on ftp server, I've tried fopen() and filesize() too, didn't work. All these three PHP functions, accepts the FTP protocol, that means the functions uses the FTP Wrapper.

So what I need to know is what's the command that this ftp wrapper sends to a FTP server to get the selected file.

Info: The ftp_get() function works fine, but it saves the file directly to a specified folder, and I just need the file content as String, that means, I need the file content but I don't want to save it to a new file.

PHP Manual

http://php.net/manual/en/wrappers.php

http://php.net/manual/en/wrappers.ftp.php


Solution

  • You could try the following answer from the PHP manual http://php.net/manual/en/function.ftp-get.php#111840:

    ob_start();
    $result = ftp_get($ftp, "php://output", $file, FTP_BINARY);
    $data = ob_get_contents();
    ob_end_clean();
    

    That should put your file in $data instead of an file.