Copy a (remote) file.

@param string $pathOld
@param string $pathNew

@throws IOException
191214
public static function copy($pathOld, $pathNew)
    {
        if (!@copy($pathOld, $pathNew)) {
            throw new IOException(sprintf("Cannot copy %s to %s", $pathOld, $pathNew));
        }
    }
1255332
public void copyDirectory(Location locn, DocPath dir)  throws DocFileIOException {
        boolean first = true;
        for (DocFile f : DocFile.list(configuration, locn, dir)) {
            if (!f.isDirectory()) {
                continue;
            }
            DocFile srcdir = f;
            DocFile destdir = DocFile.createFileForOutput(configuration, dir);
            if (srcdir.isSameFile(destdir)) {
                continue;
            }

            for (DocFile srcfile: srcdir.list()) {
                DocFile destfile = destdir.resolve(srcfile.getName());
                if (srcfile.isFile()) {
                    if (destfile.exists() && !first) {
                        messages.warning("doclet.Copy_Overwrite_warning",
                                srcfile.getPath(), destdir.getPath());
                    } else {
                        messages.notice("doclet.Copying_File_0_To_Dir_1",
                                srcfile.getPath(), destdir.getPath());
                        destfile.copyFile(srcfile);
                    }
                } else if (srcfile.isDirectory()) {
                    if (configuration.copydocfilesubdirs
                            && !configuration.shouldExcludeDocFileDir(srcfile.getName())) {
                        copyDirectory(locn, dir.resolve(srcfile.getName()));
                    }
                }
            }

            first = false;
        }
    }
2867
public void copyFileFrom(InputStream src, boolean append) throws CopyFileFromException {
        ChannelSftp sftp;

        try {
            sftp = alloc();
            try {
                sftp.put(src, escape(slashPath), append ? ChannelSftp.APPEND : ChannelSftp.OVERWRITE);
            } finally {
                free(sftp);
            }
        } catch (SftpException | JSchException e) {
            throw new CopyFileFromException(this, e);
        }
    }
1122627
public void copyToLocalFile(boolean delSrc, boolean validate,
      Path src, Path dst)
  throws IOException {
    FileUtil.copy(this, src, getLocal(getConf()), dst, delSrc,
        validate, getConf());
  }
1015251
public function uploadFile($pathFrom, $pathTo)
    {
        if ( ! $localStream = @fopen($pathFrom, 'r')) {

            throw new SftpLocalFileException("Unable to open local file: '{$pathFrom}'.");
        }

        if ( ! $remoteStream = @fopen("ssh2.sftp://{$this->ftpConnection}/{$pathTo}", 'w')) {

            throw new SftpRemoteFileException("Unable to open remote: '{$pathTo}'.");
        }

        // write from our remote stream to our local stream
        $buffer       = stream_get_contents($localStream);
        $bytesWritten = strlen($buffer);

        if (fwrite($remoteStream, $buffer) === false) {

            throw new SftpLocalFileException("Unable to write to remote file: '{$pathTo}'.");
        }

        fclose($localStream);
        fclose($remoteStream);

        event( new SshFileUploaded(basename($pathFrom), $pathTo, $bytesWritten) );

        return $bytesWritten;
    }
738520
public function copy(string $newFilePath, bool $overwrite = true): self
    {
        $newFilePath = normalize_path($newFilePath);

        if ($overwrite || !is_file($newFilePath)) {
            if (copy($this->path, $newFilePath)) {
                return new self($newFilePath);
            }
            throw new FileException('Cannot copy file to the new file path ('.$newFilePath.') for unknown reasons');
        }
        throw new FileException('Cannot copy file, because the new file path ('.$newFilePath.') already exists', FileException::ALREADY_EXIST);
    }
1282402
public Node copyFile(Node dest) throws FileNotFoundException, CopyException {
        try (OutputStream out = dest.newOutputStream()) {
            copyFileTo(out);
        } catch (FileNotFoundException e) {
            throw e;
        } catch (IOException e) {
            throw new CopyException(this, dest, e);
        }
        return this;
    }
1339518
public function copyFile($originalFile, $newFile)
    {
        if (is_file($originalFile)) {
            @copy($originalFile, $newFile) or die("File '{$originalFile}' can't be copied to '{$newFile}'.");
        } else {
            die("File '{$originalFile}' doesn't exist.");
        }
    }
357994
public static final void copyResource(String source, Path target, Class<?> cls) throws IOException
    {
        try (InputStream is = cls.getResourceAsStream(source))
        {
            Files.copy(is, target, REPLACE_EXISTING);
        }
    }
313113
public function copy($newPath = null)
    {
        if (is_null($newPath)) {
            $newPath = $this->path . '-copy';
        }

        if (@$this->filesystem->copy($this->path, $newPath)) {
            return $this->getClone()->setPath($newPath);
        } else {
            $lastError = error_get_last();
            throw new CopyFailedException($this, $newPath, $lastError['message']);
        }
    }
204999
private void copyFile(String path, File dest) {
        String resourceName= "native/" + path;
        try
        {
            LOG.debug("Copy from resource <"+resourceName+"> to target <"+dest.getAbsolutePath()+">");
            if (copy(getClass().getResourceAsStream(resourceName), dest.getAbsolutePath()))
            {
                if (dest.exists())
                {
                    LOG.debug("Target <"+dest.getAbsolutePath()+"> exists");
                }
                else
                {
                    LOG.fatal("Target <"+dest.getAbsolutePath()+"> does not exist");
                }
            }
            else
            {
                LOG.fatal("Copy resource to target <"+dest.getAbsolutePath()+"> failed");
            }
        }
        catch (NullPointerException ex)
        {
            LOG.error("Could not find ffmpeg executable for "+resourceName+" is the correct platform jar included?");
            throw ex;
        }
    }
846097
public File createNewFile() throws IOException {
        if (FileLogUtils.validateDirectory(directory) == null) {
            return null;
        }

        return rolling ? rollFile() : createNewUniqueFile(null);
    }
131781
public function move($nameold,$pathnew,$path){
        if($this->validNameFile($nameold,false) && preg_match_all("#^/{1}$|^/[a-z0-9A-Z]{1}([a-z0-9A-Z-_/])*(/|[a-z0-9A-Z-_]{1,})+$#",$pathnew) > 0){
            $nameold = $this->clearNameFile($nameold);
            $fullpath = $this->sanitizeNameFolder($this->getFullPath().$path,true);
            $fullpathnew = $this->sanitizeNameFolder($this->getFullPath().$pathnew,true);
            if( $this->config['debug'] ) $this->_log('$fullpath - '.$fullpath);
            if( $this->config['debug'] ) $this->_log('$fullpathnew - '.$fullpathnew);
            if( $this->config['debug'] ) $this->_log('$fullpath/$nameold - '.$fullpath.'/'.$nameold);
            if( $this->config['debug'] ) $this->_log('$fullpathnew/$nameold - '.$fullpathnew.'/'.$nameold);

            if($fullpath == $fullpathnew || $fullpath.'/'.$nameold==$fullpathnew.'/'.$nameold){
                if( $this->config['debug'] ) $this->_log('$path == $pathnew Equals');
                $result = array("query"=>"BE_MOVE_PATH_NOT_VALID","params"=>array());
                $this->setInfo(array("msg"=>$result, "status"=>0));
                return;
            }elseif(strpos($fullpathnew.'/'.$nameold,$fullpath.'/'.$nameold.'/')!==false ){
                if( $this->config['debug'] ) $this->_log('$pathnew internal of source - '.$pathnew);
                $result = array("query"=>"BE_MOVE_PATH_NOT_VALID","params"=>array());
                $this->setInfo(array("msg"=>$result, "status"=>0));
                return;
            }elseif(strpos($fullpath.'/'.$nameold,$fullpathnew.'/'.$nameold.'/')!==false ){
                if( $this->config['debug'] ) $this->_log('$pathnew not moved in same folder - '.$pathnew);
                $result = array("query"=>"BE_MOVE_PATH_NOT_VALID","params"=>array());
                $this->setInfo(array("msg"=>$result, "status"=>0));
                return;
            }
            $file = new Filesystem;
            if($file->exists($fullpath.'/'.$nameold)){
                if(is_dir($fullpath.'/'.$nameold)){
                    if($file->exists($fullpathnew.'/'.$nameold)===false){
                        if($file->exists($fullpathnew)==false){
                            $file->mkdir($fullpathnew);
                        }
                        $file->rename($fullpath.'/'.$nameold,$fullpathnew.'/'.$nameold);
                        $result = array("query"=>"BE_MOVE_MOVED","params"=>array());
                        $fullpathnew_result = $this->sanitizeNameFolder($pathnew.'/'.$nameold,true);
                        $this->setInfo(array("msg"=>$result,"data"=>array("namefile" => $fullpathnew_result)));
                    }else{
                        $result = array("query"=>"BE_MOVE_FOLDER_EXISTED","params"=>array());
                        $this->setInfo(array("msg"=>$result, "status"=>0));
                    }

                }elseif(is_file($fullpath.'/'.$nameold)){
                    if($this->validExt($nameold)){
                        if($file->exists($fullpathnew.'/'.$nameold)===false){
                            if($file->exists($fullpathnew)==false){
                                $file->mkdir($fullpathnew);
                            }
                            $file2 = new \SplFileInfo($fullpath.'/'.$nameold);
                            if(in_array($file2->getExtension(), $this->config['images']['images_ext'])){
                                $filename = $file2->getFilename();
                                foreach ($this->config['images']['resize'] as $key => $value) {
                                    $image_info = $this->imageSizeName($path,$filename,$value);
                                    $filename_old = $image_info['name'];
                                    $fullpaththumb_name = $this->getFullPath().'/'.$this->config['folder_thumb'].$path.$filename_old;
                                    $file->remove($fullpaththumb_name);
                                }
                            }
                            $file->rename($fullpath.'/'.$nameold,$fullpathnew.'/'.$nameold);
                            $result = array("query"=>"BE_MOVE_MOVED","params"=>array());
                            $fullpathnew_result = $this->sanitizeNameFolder($pathnew.'/'.$nameold,true);
                            $this->setInfo(array("msg"=>$result,"data"=>array("namefile" => $fullpathnew_result)));
                        }else{
                            $result = array("query"=>"BE_MOVE_EXISTED","params"=>array());
                            $this->setInfo(array("msg"=>$result, "status"=>0));
                        }
                    }else{
                        $result = array("query"=>"BE_MOVE_FILENAME_NOT_VALID","params"=>array());
                        $this->setInfo(array("msg"=>$result, "status"=>0));
                    }
                }
            }else{
                $result = array("query"=>"BE_MOVE_NOT_EXISTS","params"=>array());
                $this->setInfo(array("msg"=>$result, "status"=>0));
            }
        }else{
            $result = array("query"=>"BE_MOVE_FILENAME_NOT_VALID","params"=>array());
            $this->setInfo(array("msg"=>$result, "status"=>0));
        }
    }
1186341
public static void copyFile(File src, File dest) throws IOException {

        if (src == null)
            throw new NullPointerException("Source must not be null");
        if (dest == null)
            throw new NullPointerException("Destination must not be null");
        if (!src.exists())
            throw new FileNotFoundException("Source '" + src + "' does not exist");
        if (!src.isFile())
            throw new IOException("Source '" + src + "' is not a file");
        if (dest.exists())
            throw new IOException("Destination '" + dest + "' is already exists");

        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(src).getChannel();
            out = new FileOutputStream(dest).getChannel();

            in.transferTo(0, in.size(), out);
        } finally {
            try {
                in.close();
                out.close();
            } catch (IOException e) {
                // Ignore.
            }
        }

        if (src.length() != dest.length()) {
            throw new IOException("Failed to copy full contents from '" +
                src + "' to '" + dest + "'");
        }

        dest.setLastModified(src.lastModified());
    }
1357077
public static boolean copyFile(final File src, final File dest)
    throws FileNotFoundException, IOException {
        return copyFile(src, dest, -1, true);
    }
892262
async function copyNewerSingle(srcpath, destpath, opts) {

  let { interval = 1000, verbose = false } = opts

  let stat = await FS.stat(srcpath)
  // Stat and check the filesystem entry type.
  if (stat.isDirectory()) {
    // Directory, ensure destination exists and return.
    let made = await mkdirp(destpath)
    if (verbose && made) { console.log(`${made} - directory created`)}
    return 'dir'
  }
  else if (!stat.isFile()) {
    // Not a file.
    throw new Error("Not supported.")
  }

  let srcmtime = stat.mtime
  let destmtime
  try {
    // Stat destpath and get the mtime.
    destmtime = (await FS.stat(destpath)).mtime
  }
  catch (err) {
    // path does not exist
  }

  if (destmtime !== undefined && srcmtime - destmtime <= interval) {
    // destpath does not exist or mtime is equal, return.
    if (verbose) { console.log(`${srcpath} == ${destpath}`) }
    return false
  }

  // Ensure parent directory exists.
  await mkdirp(`${destpath}/..`)

  // Commence copying.
  let rs = FS.createReadStream(srcpath)
  let ws = FS.createWriteStream(destpath)
  rs.pipe(ws)
  await waitForStreamEnd(ws)

  // Set mtime to be equal to the source file.
  await FS.utimes(destpath, new Date(), stat.mtime)

  if (verbose) { console.log(`${srcpath} -> ${destpath}`) }
  return true
}
29476
function copyFile(srcPath, desPath) {
    var read = fs.createReadStream(srcPath);
    var write = fs.createWriteStream(desPath);
    read.pipe(write);
    console.log('[info] create file:', desPath);
}