Hi,
I am quite new to PHP (but have experience with perl etc) and am facing
a certain issue with PHP 4.2.1's ftp function.
I am trying to extend a program to fetch a file from a remote server.
I tried:
ob_start();
$retval = @readfile("ftp://$user:$pass@$server:$port/$filename")
if (false != $retval) {
$contents = ob_get_contents()
}
ob_end_clean();
Here the problem is that PHP seems to want to execute a
SIZE /$filename
on the server instead of the correct
SIZE $filename
Using ftp_get I get a different error. Executing this code:
if (!($ftpConnection = @ftp_connect($server,$port))) {
$this->err_str = _("Server connection failed");
return false;
}
if (!(@ftp_login($ftpConnection, $user, $pass))) {
$this->err_str = _("Could not login - check password!");
@ftp_quit($ftpConnection);
return false;
}
if (!(@ftp_get($ftpConnection, $dst, $src, $mode))) {
$this->err_str = _("Could not get file!");
@ftp_quit($ftpConnection);
return false;
}
with a pre-created tempfile (tempnam) as $dst.
the FTP server (proftpd) logs a proper file transfer of n bytes
but the received tempfile is empty and ftp_get returns a FALSE
status.
I cannot however find any further indication of the problem
(such as an error variable or string pinpointing the cause).
I ended up using a
system("wget -O $tempfile ftp://$user:$pass@$server:$port/$filename")
which works a charm but is ugly.
I also find that the ftp_get takes a long time to return. the proftpd
server has long logged a successful transfer and session closure, yet
the function does not return.
does anyone have any hints what could be wrong?
thanks