You are here: Re: PHP-FTP Downloading Files « PHP Programming Language « IT news, forums, messages
Re: PHP-FTP Downloading Files

Posted by Kim Andrι Akerψ on 10/31/06 16:24

Vic Spainhower 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.
>
> 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);

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ΓΈ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация