FTP copy a file to another place in same FTP

前端 未结 9 2036
闹比i
闹比i 2020-11-28 11:54

I need to upload same file to 2 different place in same FTP. Is there a way to copy the file on the FTP to the other place instead of upload it again? Thanks.

相关标签:
9条回答
  • 2020-11-28 12:41

    Here's another workaround using PHP cUrl to execute a copy request on the server by feeding parameters from the local machine and reporting the outcome:

    Local code: In this simple test routine, I want to copy the leaning tower photo to the correct folder, Pisa:

    $ch = curl_init();
    $data = array ('pic' => 'leaningtower', 'folder' => 'Pisa');
    curl_setopt($ch, CURLOPT_URL,"http://travelphotos.com/copypic.php");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch,  CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $result = curl_exec($ch);
    curl_close($ch);
    echo $result;
    

    Server code (copypic.php): On the remote server, I have simple error checking. On this server I had to mess with the path designation, i.e., I had to use "./" for an acceptable path reference, so you may have to tinker with it a bit.

    $pic = $_POST["pic"];
    $folder = $_POST["folder"];
    if (!$pic || !$folder) exit();
    
    $sourcePath = "./unsortedpics/".$pic.".jpg";
    $destPath =   "./sortedpics/".$folder."/".$pic.".jpg";
    
    if (!file_exists($sourcePath )) exit("Source file not found");
    if (!is_dir("./sortedpics/".$folder)) exit("Invalid destination folder");
    if (!copy($sourcePath , $destPath)) exit("Copy not successful");
    echo "File copied";
    
    0 讨论(0)
  • 2020-11-28 12:43

    You can do this from C-Panel.

    1. Log into your C-Panel.
    2. Go into file manager.
    3. Find the file or folder you want to duplicate.
    4. Right-click and chose Copy.
    5. Type in the new director you want to copy to.

    Done!

    0 讨论(0)
  • 2020-11-28 12:45

    You can rename the file to be copied into the full path of your wanted result.

    For example: If you want to move the file "file.txt" into the folder "NewFolder" you can write it as

    ftp> rename file.txt NewFolder/file.txt
    

    This worked for me.

    0 讨论(0)
提交回复
热议问题