如何使用 phpseclib 复制或移动远程文件? [英] How do I copy or move remote files with phpseclib?
本文介绍了如何使用 phpseclib 复制或移动远程文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚为自己发现了 phpseclib,并希望将它用于我的代码.不知何故,我不知道如何将文件从一个 sftp 目录复制到另一个 sftp 目录.如果你能帮我解决这个问题就好了.
I've just discovered phpseclib for myself and would like to use it for my bit of code. Somehow I can't find out how I could copy files from one sftp directory into an other sftp directory. Would be great if you could help me out with this.
例如:
复制所有文件
/jn/xml/
到
/jn/xml/backup/
推荐答案
$dir = "/jn/xml/";
$files = $sftp->nlist($dir, true);
foreach($files as $file)
{
if ($file == '.' || $file == '..') continue;
$sftp->put($dir."backup".'/'.$file, $sftp->get($dir.'/'.$file);
}
这段代码会将内容从/jn/xml/"目录复制到/jn/xml/backup".
This code will copy contents from "/jn/xml/" directory to "/jn/xml/backup".
这篇关于如何使用 phpseclib 复制或移动远程文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文