简体   繁体   English

如何在 PHP 中移动 SFTP 服务器上的文件

[英]How I can move file on a SFTP server in PHP

How can I move a file from one directory into another directory?如何将文件从一个目录移动到另一个目录?

I have try this, but it doesn't work:我试过这个,但它不起作用:

$success = @rename('ssh2.sftp://' . $sftp . $path_from, 'ssh2.sftp://' . $sftp . $path_to);
if ($success) {
    echo "moving success!";
}else {
    echo "moving failed!";
}

I'm using PHP SSH2 functions.我正在使用 PHP SSH2 函数。

Can someone help me?有人能帮我吗?

Use ssh2_sftp_rename :使用ssh2_sftp_rename

ssh2_sftp_rename($sftp, $path_from, $path_to);

Assuming both variables contain full paths to files, eg like:假设两个变量都包含文件的完整路径,例如:

$path_from = "/source/directory/myfile.txt";
$path_to = "/destination/directory/myfile.txt";

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

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