ftp_get

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BobBlightman
Forum Newbie
Posts: 3
Joined: Thu Feb 19, 2015 2:33 am

ftp_get

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: ftp_get

Post 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)?
BobBlightman
Forum Newbie
Posts: 3
Joined: Thu Feb 19, 2015 2:33 am

Re: ftp_get

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: ftp_get

Post 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...
BobBlightman
Forum Newbie
Posts: 3
Joined: Thu Feb 19, 2015 2:33 am

Re: ftp_get

Post by BobBlightman »

thanks for clarifying this

Can you tell me how to present the download prompt to the user?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: ftp_get

Post 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
Post Reply