Home > Archive > PHP Language > October 2006 > PHP FTP - Download to local machine
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
PHP FTP - Download to local machine
|
|
| Vic Spainhower 2006-10-31, 6:57 pm |
| Hello,
I am trying to download a file to my local machine using PHP. However, when
the script runs the file is placed in the folder assigned to the ftp user on
the Web server instead of downloading to my local C drive. After the
following script runs I find a file named C:\TestShowID.txt in the user's
FTP folder on the web server. Can some tell me why this happens? The local
machine is a Windows XP machine.
Thanks,
Vic
$ftp = (object) array(
"host" => "ftp.mydomain.com",
"user" => "user@mydomain.net",
"password" => "password",
"remoteFile" => "ShowID.txt",
"localFile" => "C:\\TestShowID.txt"
);
// Step one: Connect to the FTP server
if(!is_resource($remoteRsrc=@ftp_connect
($ftp->host)))
trigger_error("Could not connect to remote "
. "server {$ftp->host}", E_USER_ERROR );
// Step two: Log into the server
if( !@ftp_login($remoteRsrc,$ftp->user,$ftp->password))
trigger_error("Could not log on to remote "
. "server {$ftp->host}", E_USER_ERROR );
// Step Three: Attempt to copy remote file to local file
if(@ftp_get($remoteRsrc,$ftp->localFile,$ftp->remoteFile,FTP_BINARY))
echo "Remote file successfully written to {$ftp->localFile}";
else
trigger_error("Could not import remote file.",E_USER_ERROR);
// Step Four: Close the connection
ftp_close($remoteRsrc);
| |
| AlexVN 2006-10-31, 6:57 pm |
|
On Oct 31, 5:36 pm, "Vic Spainhower" <v...@showsec.com> wrote:
> Hello,
>
> I am trying to download a file to my local machine using PHP. However, when
> the script runs the file is placed in the folder assigned to the ftp user on
> the Web server instead of downloading to my local C drive. After the
> following script runs I find a file named C:\TestShowID.txt in the user's
> FTP folder on the web server. Can some tell me why this happens? The local
> machine is a Windows XP machine.
You are executing script on the server, right? So the file appears on
the server. You cannot use the PHP functions like they are executed on
user's computer. The best you can do it to set proper content encoding
header and print the content of the downloaded file.
Sincerely,
Alexander
http://www.alexatnet.com/ - PHP/ZendFramework and Ajax blog
|
|
|
|
|