Page 1 of 1

ftp_get

Posted: Thu Feb 19, 2015 2:38 am
by BobBlightman
I'm a relative beginner to php, so bear with me

I'm trying to download a file from the server to my local pc. Here's my code:
$local_file = 'c:\cirwin\rcc\test.dat';
// download server file
if (ftp_get($ftp_conn, $local_file, $filename, FTP_ASCII))
{
echo "Successfully written to $local_file.";
}
else
{
echo "Error downloading $server_file.";
}

// close connection
ftp_close($ftp_conn);

I'm getting the message that the file has been successfully written, but I can't find it on my local machine. Any thoughts?

Re: ftp_get

Posted: Thu Feb 19, 2015 3:41 am
by requinix
Are you running this PHP code on your local machine too? How: Apache/IIS (using a browser) or not (using the command-line)?

Re: ftp_get

Posted: Thu Feb 19, 2015 4:02 am
by BobBlightman
Thanks for the reply

No - I'm using the Internet site that the php code is running on (like one of the users for who I'm developing the site would).

I did discover that in some cases it appeared to have written the file to the server on the web site, but now it doesn't do that either

Any help you can give greatly appreciated

Bob

Re: ftp_get

Posted: Thu Feb 19, 2015 4:54 am
by requinix
You're subject to file permissions so there's no guarantee the file will be created, but yes: it happens on the computer running PHP, so if you're running it on some server then the file will be downloaded to the server. If you ran it on your own computer then the file would be downloaded to your own computer.

If PHP is running on a server then you can't force a download to your own computer, but you can present a file download prompt in the browser...

Re: ftp_get

Posted: Thu Feb 19, 2015 4:57 am
by BobBlightman
thanks for clarifying this

Can you tell me how to present the download prompt to the user?

Re: ftp_get

Posted: Thu Feb 19, 2015 5:58 am
by Celauran
Once you've downloaded the remote file, you'll need to get the MIME type, set the appropriate headers, and then either echo the file contents or send to php://output