简体   繁体   中英

Using ftp_fget using SFTP / phpseclib

I'm currently having a horrible time with SFTP. Is there a way to use ftp_fget using SFTP?

I'm using the phpseclibrary, but it only offers their own implementation of $sftp->get() howver I would like $sftp->fget();

In the latest Git version (ie. later than 0.3.7), instead of $sftp->fget() , you can do something like this:

$fp = fopen('filename.ext', 'w');
$sftp->get('file_to_download.ext', $fp);
fclose($fp);

You could also alternatively use Net/SFTP/Stream.php . eg.

$resFile = fopen("sftp://{$resSFTP}/".$filename, 'w');
$srcFile = fopen("/home/myusername/".$filename, 'r');
$writtenBytes = stream_copy_to_stream($srcFile, $resFile);
fclose($resFile);
fclose($srcFile);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM