简体   繁体   中英

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.

Can someone help me?

Use 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";

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