开发者

download a file asynchronously using FTP

开发者 https://www.devze.com 2023-02-02 08:54 出处:网络
Which function to you use to download a file asynchronously开发者_StackOverflow using FTP and save it locally?Really quick idea:

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


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.


  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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号