Hej alle
Jeg forsøger at kopier en mappe der ligger et andet sted på ftp'en til en ny destination..
Men der sker intet håber i kan hjælpe mig!
- <?php
-
-
- $tags = mysqli_query($conn, "SELECT domaine FROM `domains` ORDER BY rand() LIMIT 1; ") or die(mysqli_error($conn));
- while($row = mysqli_fetch_array($tags))
- {
- $domainresul = $row['domaine'];
- }
-
- function random_string($length) {
- $key = '';
- $keys = array_merge(range(0, 9), range('a', 'z'));
-
- for ($i = 0; $i < $length; $i++) {
- $key .= $keys[array_rand($keys)];
- }
-
- return $key;
- }
-
-
- $file = "index.php";
- $content = $sideindhold;
-
-
- if (isset($_POST['submit'])) {
-
-
- $ftp_server = "xxx"; // virtuelt doamin
- $conn_id = ftp_connect($ftp_server);
- $ftp_user_name = "xxx"; // bruger jeg har opsat på min xampp, med rettigheder til example.com
- $ftp_user_pass = "xxx";
- $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
-
- // $root="url/phptest";
- $root = $domainresul;
-
-
-
-
- /* **************************************** */
- /* create a stream context telling PHP to overwrite the file */
- $options = array('ftp' => array('overwrite' => true));
- $stream = stream_context_create($options);
- /* **************************************** */
-
-
- // check connection
- echo "<center>";
- if ((!$conn_id) || (!$login_result)) {
- echo '<div style="background-color:red;padding:10px;color:#fff;font-size:16px;">';
- echo "FTP connection has failed!";
- echo "Attempted to connect to <b>$ftp_server</b> for user <b>$ftp_user_name</b>";
- echo '</div>';
- } else {
-
- $foldername1 = random_string(4);
- $foldername2 = random_string(3);
- $foldername3 = random_string(2);
-
-
-
- $directory = "$root/$foldername1";
-
- if (ftp_mkdir($conn_id, $directory)) {
-
- $directory = "$root/$foldername1/$foldername2";
-
- if (ftp_mkdir($conn_id, $directory)) {
-
- $directory = "$root/$foldername1/$foldername2/$foldername3";
-
-
- if (ftp_mkdir($conn_id, $directory)) {
- /* **************************************** */
- /* and finally, put the contents */
- $hostname2 = "ftp://" . $ftp_user_name . ":" . $ftp_user_pass . "@" . $ftp_server . "/";
- $hostname = "ftp://" . $ftp_user_name . ":" . $ftp_user_pass . "@" . $ftp_server . "/" . $directory . "/";
-
-
- $src = $hostname2 . "xxx.xxx/se";
- $dst = $hostname;
-
- echo $src;
- echo $dst;
-
- shell_exec("cp -r $src $dest");
-
- /* **************************************** */
-
- }
- }
- } else {
- echo '<div style="background-color:red;padding:10px;color:#fff;font-size:16px">';
- echo "Could not create directory: <b>$directory</b>";
- echo '</div>';
- }
- }
- echo "</center>";
- }
- ?>
Indlæg senest redigeret d. 12.04.2017 16:01 af Bruger #21714