Poonam Bhatt
Poonam Bhatt

Reputation: 10302

download a file asynchronously using FTP

Which function to you use to download a file asynchronously using FTP and save it locally?

Upvotes: 0

Views: 878

Answers (2)

foo
foo

Reputation: 2111

  1. have a look at http://php.net/manual/en/book.ftp.php

  2. if you still need help, please try to make it clear what exactly it is you want. For example, what you mean by "asynchronously" in the context of PHP - you are aware PHP usually does no threading and each script times out fast?

Upvotes: 0

Luke Stevenson
Luke Stevenson

Reputation: 10341

Really quick idea:

// Assumed Variables and Values
// $ftpUser = 'FTP_Username'; or FALSE if not needed
// $ftpPass = 'FTP_Password'; or FALSE is not needed
// $ftpHost = 'FTP_Hostname';
// $ftpFile = 'FTP_Filename';
// $locFile = 'Local File Location, from Root';
$wgetCommand = 'wget ftp://'.
               ( $ftpUser ? $ftpUser.':'.$ftpPass : '' ).
               '@'.$ftpHost.'/'.$ftpFile.
               ' -O '.$locFile;
command( $wgetCommand.' &' );

The ampersand at the end of the command means to execute the command in the background and not to wait for a response, this should produce the "async" performance you request.

Upvotes: 2

Related Questions