简体   繁体   中英

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. A user on test.com check the images and then move this whole image folder on 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.

//you can use ssh connect like this

<?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. 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.

http://php.net/manual/en/function.exec.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.

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