PHP-FTP Downloading Files

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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.



$ftp = (object) array(
  "host"       =>  "",
  "user"       =>  "",
  "password"   =>  "password",
  "remoteFile" =>  "ShowID.txt",
  "localFile"  =>  "C:\TestShowID.txt"
// Step one: Connect to the FTP server
   trigger_error("Could not connect to remote "
   . "server ", 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 ", E_USER_ERROR );

// Step Three: Attempt to copy remote file to local file
   echo "Remote file successfully written to ";
   trigger_error("Could not import remote file.",E_USER_ERROR);

// Step Four: Close the connection

Re: PHP-FTP Downloading Files

Vic Spainhower wrote:

Quoted text here. Click to load it

If you've read the PHP manual, you'll see that ftp_get() retrieves the
remote file (on the FTP server PHP is connecting to) and saves it as
the local file (on the machine running the PHP script).

If you've uploaded the PHP script to a web server, "local" is defined
as the web server, and subsequentally the user FTP folder.

Kim André Akerø
(remove NOSPAM to contact me directly)

Site Timeline