简体   繁体   English

PHP脚本将目录从一台Linux服务器移至另一台?

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

I have an image folder on my test.com/images/item1 with 2-3 sub folder in it. 我在test.com/images/item1上有一个图像文件夹,其中有2-3个子文件夹。 A user on test.com check the images and then move this whole image folder on test2.com/images/. test.com上的用户检查图像,然后将整个图像文件夹移到test2.com/images/上。

Now i did it with command prompt. 现在,我使用命令提示符进行了操作。 But i need a php script which move or copy this image folder on one server to another using php script. 但是我需要一个php脚本,该脚本使用php脚本将映像文件夹移动或复制到一台服务器上。

//you can use ssh connect like this //您可以像这样使用ssh connect

<?php
       $connection = ssh2_connect('shell.example.com', 22);
       ssh2_auth_password($connection, 'username', 'password');

       ssh2_scp_send($connection, '/local/filename', '/remote/filename', 0644);
?>

该工具rsync将为您提供简要的用法:system('rsync -Rtp文件名> target_server :: module')

The answer to your Question is "Yes", you can Exec or SSH or FTP, or SFTP, you can do all these depending on your situation and requirement. 您问题的答案是“是”,您可以执行,SSH,FTP或SFTP,根据您的情况和要求执行所有这些操作。 Ask complete question to what you want us to help with :). 完整询问您希望我们提供什么帮助的:)。

there are many ways to do this but the easiest seems to be to send your cmd with php's exec or passthru function. 有很多方法可以做到这一点,但最简单的方法似乎是使用php的exec或passthru函数发送cmd。

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

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

Warning 警告

When allowing user-supplied data to be passed to this function, use escapeshellarg() or escapeshellcmd() to ensure that users cannot trick the system into executing arbitrary commands. 当允许用户提供的数据传递给此函数时,请使用escapeshellarg()或escapeshellcmd()来确保用户不会诱使系统执行任意命令。

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

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