I am trying to download a file using FTP in PHP CLI. I have no access to the server where I'm downloading from.
Here's some information about my system.
$ php -v
PHP 5.5.12 (cli) (built: Aug 16 2014 11:36:51) (DEBUG)
$ cat /etc/*-release
NAME="Red Hat Enterprise Linux Server"
VERSION="7.0 (Maipo)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="7.0"
PRETTY_NAME="Red Hat Enterprise Linux Server 7.0 (Maipo)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:7.0:GA:server"
HOME_URL="https://www.redhat.com/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
REDHAT_BUGZILLA_PRODUCT_VERSION=7.0
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION=7.0
Red Hat Enterprise Linux Server release 7.0 (Maipo)
Red Hat Enterprise Linux Server release 7.0 (Maipo)
Here's the code.
$ftpconn = ftp_connect(FTP_HOST);
ftp_set_option($ftpconn, FTP_TIMEOUT_SEC, 86000);
$ftplogin = ftp_login($ftpconn, FTP_USER, FTP_PASS);
ftp_pasv($ftpconn, true);
$list = ftp_nlist($ftpconn, FTP_PATH);
foreach($list as $file){
ftp_get($ftpconn, DOWNLOAD_PATH . DIRECTORY_SEPARATOR . $file, $file, FTP_BINARY)
}
When the script hits ftp_get
the file is created with the proper name, but then it hangs for the amount of time specified in ftp_set_option
. PHP never writes anything to the file.
I have set 777 permission for the root folder where it's located recursively. I'm also running PHP CLI as root.
sudo php /path/to/php/file.php
Is this a problem with PHP being unable to write to the file? Why is it not throwing any errors? When the timeout is reached, the ftp_get
function simply returns false.
Help would be greatly appreciated.