简体   繁体   English

使用SFTP / phpseclib使用ftp_fget

[英]Using ftp_fget using SFTP / phpseclib

I'm currently having a horrible time with SFTP. 我目前在SFTP上度过了一段糟糕的时光。 Is there a way to use ftp_fget using SFTP? 有没有办法使用SFTP使用ftp_fget?

I'm using the phpseclibrary, but it only offers their own implementation of $sftp->get() howver I would like $sftp->fget(); 我使用的是phpseclibrary,但是它只提供了自己的$sftp->get()实现,而我想要$sftp->fget();

In the latest Git version (ie. later than 0.3.7), instead of $sftp->fget() , you can do something like this: 在最新的Git版本(即0.3.7之后$sftp->fget() ,您可以执行以下操作,而不是$sftp->fget()

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

You could also alternatively use Net/SFTP/Stream.php . 您也可以选择使用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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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