PHP脚本,用于将目录从一个Linux服务器移动到另一个服务器


PHP script to move a directory from one Linux server to another?

我的test.com/images/item1上有一个图像文件夹,其中有2-3个子文件夹。test.com上的用户检查图像,然后将整个图像文件夹移动到test2.com/images/.上

现在我用命令提示符完成了。但我需要一个php脚本,它可以使用php脚本将一台服务器上的图像文件夹移动或复制到另一台服务器。

//您可以像这样使用ssh连接

<?php
       $connection = ssh2_connect('shell.example.com', 22);
       ssh2_auth_password($connection, 'username', 'password');
       ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644);
?>

rsync工具将为您提供帮助,简要介绍用法:系统('sync-Rtp filename>target_server::module')

问题的答案是"是",您可以执行或SSH、FTP或SFTP,您可以根据您的情况和要求执行所有这些操作。向您希望我们帮助的内容提出完整的问题:)。

有很多方法可以做到这一点,但最简单的方法似乎是使用php的exec或passthrough函数发送cmd。

http://php.net/manual/en/function.exec.php

http://www.php.net/manual/en/function.passthru.php

警告

当允许用户提供的数据传递到此函数时,使用escapeshellarg()或escapeshellcmd(),以确保用户不会欺骗系统执行任意命令。

相关文章: