scp the local file to remote folder.

        :param local_path: local path
        :param remote_path: remote path
199376
def copy_file_to_remote(self, local_path, remote_path):
        
        sftp_client = self.transport.open_sftp_client()
        LOG.debug('Copy the local file to remote. '
                  'Source=%(src)s. Target=%(target)s.' %
                  {'src': local_path, 'target': remote_path})
        try:
            sftp_client.put(local_path, remote_path)
        except Exception as ex:
            LOG.error('Failed to copy the local file to remote. '
                      'Reason: %s.' % six.text_type(ex))
            raise SFtpExecutionError(err=ex)
190142
def put(self, local, remote, contents=None, quiet=False):
        
        remote_dir = os.path.dirname(remote)
        remote_file = os.path.basename(local)\
            if remote.endswith('/') else os.path.basename(remote)

        if contents:
            # local is ignored if contents is set
            local_file = buffer_type(contents)
        elif isinstance(local, file_type):
            local_file = local
        else:
            local_file = open(local, 'rb')
        current = self.conn.pwd()
        self.descend(remote_dir, force=True)

        size = 0
        try:
            self.conn.storbinary('STOR %s' % remote_file, local_file)
            size = self.conn.size(remote_file)
        except:
            if not quiet:
                raise
        finally:
            local_file.close()
            self.conn.cwd(current)
        return size
311446
def put_file(self, in_path, out_path):
        '''  '''
        vvv("PUT %s TO %s" % (in_path, out_path), host=self.host)
        if not os.path.exists(in_path):
            raise errors.AnsibleFileNotFound("file or module does not exist: %s" % in_path)
        try:
            self.sftp = self.ssh.open_sftp()
        except:
            raise errors.AnsibleError("failed to open a SFTP connection")
        try:
            self.sftp.put(in_path, out_path)
        except IOError:
            raise errors.AnsibleError("failed to transfer file to %s" % out_path)
190914
def local_cache_path(remote_url):
    """"""
    local_name = RESERVED_PATH_CHARS.sub("_", remote_url)
    return os.path.join(gettempdir(), local_name)
893891
def copy_from_server_to_local(dataset_remote_dir, dataset_local_dir,
                              remote_fname, local_fname):
    
    log.debug("Copying file `{}` to a local directory `{}`."
              .format(remote_fname, dataset_local_dir))

    head, tail = os.path.split(local_fname)
    head += os.path.sep
    if not os.path.exists(head):
        os.makedirs(os.path.dirname(head))

    shutil.copyfile(remote_fname, local_fname)

    # Copy the original group id and file permission
    st = os.stat(remote_fname)
    os.chmod(local_fname, st.st_mode)
    # If the user have read access to the data, but not a member
    # of the group, he can't set the group. So we must catch the
    # exception. But we still want to do this, for directory where
    # only member of the group can read that data.
    try:
        os.chown(local_fname, -1, st.st_gid)
    except OSError:
        pass

    # Need to give group write permission to the folders
    # For the locking mechanism
    # Try to set the original group as above
    dirs = os.path.dirname(local_fname).replace(dataset_local_dir, '')
    sep = dirs.split(os.path.sep)
    if sep[0] == "":
        sep = sep[1:]
    for i in range(len(sep)):
        orig_p = os.path.join(dataset_remote_dir, *sep[:i + 1])
        new_p = os.path.join(dataset_local_dir, *sep[:i + 1])
        orig_st = os.stat(orig_p)
        new_st = os.stat(new_p)
        if not new_st.st_mode & stat.S_IWGRP:
            os.chmod(new_p, new_st.st_mode | stat.S_IWGRP)
        if orig_st.st_gid != new_st.st_gid:
            try:
                os.chown(new_p, -1, orig_st.st_gid)
            except OSError:
                pass
941262
def _scp_file(self, source_file, dest_file, file_system):
        
        return self._xfer_file(
            source_file=source_file,
            dest_file=dest_file,
            file_system=file_system,
            TransferClass=FileTransfer,
        )
232662
def _transfer_data(self, remote_path, data):
        
        if isinstance(data, dict):
            data = jsonify(data)
        if not isinstance(data, bytes):
            data = to_bytes(data, errors='surrogate_or_strict')

        LOG.debug('_transfer_data(%r, %s ..%d bytes)',
                  remote_path, type(data), len(data))
        self._connection.put_data(remote_path, data)
        return remote_path
249672
def upload_module(self, local_path=None, remote_path="/tmp/lime.ko"):
        
        if local_path is None:
            raise FileNotFoundFoundError(local_path)
        self.shell.upload_file(local_path, remote_path)
757371
def remove(self, remote_path):
        
        # Based on the remote file stats; remove a file or directory recursively
        ftp = self.ssh.open_sftp()
        if stat.S_ISDIR(ftp.stat(remote_path).st_mode):
            self.__remove_dir(ftp, remote_path)
        else:
            ftp.remove(remote_path)
        ftp.close()
589707
def upload(self, local_fn: str, remote_fn: str = '',
             dont_overwrite: bool = False) -> None:
    """"""

    # support wildcard through glob
    if '*' in local_fn:
      for local_subfn in glob.glob(local_fn):
        self.upload(local_subfn)
      return

    if '#' in local_fn:  # hashes also give problems from shell commands
      self.log("skipping backup file {local_fn}")
      return

    if not self.sftp:
      self.sftp = u.call_with_retries(self.ssh_client.open_sftp,
                                      'self.ssh_client.open_sftp')

    def maybe_fix_mode(local_fn_, remote_fn_):
      """Makes remote file execute for locally executable files"""
      mode = oct(os.stat(local_fn_)[stat.ST_MODE])[-3:]
      if '7' in mode:
        self.log(f"Making {remote_fn_} executable with mode {mode}")
        # use raw run, in case tmux is unavailable
        self._run_raw(f"chmod {mode} {remote_fn_}")

    # augmented SFTP client that can transfer directories, from
    # https://stackoverflow.com/a/19974994/419116
    def _put_dir(source, target):
      """ Uploads the contents of the source directory to the target path."""

      def _safe_mkdir(path, mode=511, ignore_existing=True):
        """ Augments mkdir by adding an option to not fail if the folder exists  asdf asdf asdf as"""
        try:
          self.sftp.mkdir(path, mode)
        except IOError:
          if ignore_existing:
            pass
          else:
            raise

      assert os.path.isdir(source)
      _safe_mkdir(target)

      for item in os.listdir(source):
        if os.path.isfile(os.path.join(source, item)):
          self.sftp.put(os.path.join(source, item), os.path.join(target, item))
          maybe_fix_mode(os.path.join(source, item), os.path.join(target, item))
        else:
          _safe_mkdir(f'{target}/{item}')
          _put_dir(f'{source}/{item}', f'{target}/{item}')

    if not remote_fn:
      remote_fn = os.path.basename(local_fn)

    self.log('uploading ' + local_fn + ' to ' + remote_fn)
    remote_fn = remote_fn.replace('~', self.homedir)

    if '/' in remote_fn:
      remote_dir = os.path.dirname(remote_fn)
      assert self.exists(
        remote_dir), f"Remote dir {remote_dir} doesn't exist"
    if dont_overwrite and self.exists(remote_fn):
      self.log("Remote file %s exists, skipping" % (remote_fn,))
      return

    assert os.path.exists(local_fn), f"{local_fn} not found"
    if os.path.isdir(local_fn):
      _put_dir(local_fn, remote_fn)
    else:
      assert os.path.isfile(local_fn), "%s is not a file" % (local_fn,)
      # this crashes with IOError when upload failed
      if self.exists(remote_fn) and self.isdir(remote_fn):
        remote_fn = remote_fn + '/' + os.path.basename(local_fn)
      self.sftp.put(localpath=local_fn, remotepath=remote_fn)
      maybe_fix_mode(local_fn, remote_fn)
100304
def cache_local_file(self, path, **kwargs):
        '''
        
        '''
        dest = os.path.join(self.opts['cachedir'], 'localfiles',
                            path.lstrip('/'))
        destdir = os.path.dirname(dest)

        if not os.path.isdir(destdir):
            os.makedirs(destdir)

        shutil.copyfile(path, dest)
        return dest
197328
public void get(String remoteFiles[], String localTargetDirectory) throws IOException {
        Session sess = null;

        if ((remoteFiles == null) || (localTargetDirectory == null))
            throw new IllegalArgumentException("Null argument.");

        if (remoteFiles.length == 0)
            return;

//        String cmd = "scp -f -r";
        String cmd = "scp -f ";

        for (int i = 0; i < remoteFiles.length; i++) {
            if (remoteFiles[i] == null)
                throw new IllegalArgumentException("Cannot accept null filename.");

            cmd += (" " + remoteFiles[i]);
        }

        try {
            sess = conn.openSession();
            sess.execCommand(cmd);
            receiveFiles(sess, remoteFiles, localTargetDirectory);
            sess.close();
        } catch (IOException e) {
            if (sess != null)
                sess.close();

            throw (IOException) new IOException("Error during SCP transfer.").initCause(e);
        }
    }
1207584
def put(self, local_path, path, atomic=True):
        
        self._connect()

        if self.sftp:
            self._sftp_put(local_path, path, atomic)
        else:
            self._ftp_put(local_path, path, atomic)

        self._close()
380196
def file_url_to_local_path(file_url):
    
    parts = urlparse(file_url)
    path = unquote(parts.path)
    if path.startswith('/') and not path.startswith('//'):
        if ON_DARWIN:
            return path
        if len(parts.netloc) == 2 and parts.netloc[1] == ':':  # Drive letter and colon.
            return parts.netloc + path
        return 'C:' + path  # Assume C drive if it's just a path starting with /.
    if len(path) > 2 and path[1] == ':':
        return path
1174267
def calculate_path(self, remote_path, input_type):
        
        directory, allow_nested_files = self._directory_for_file_type(input_type)
        path = get_mapped_file(directory, remote_path, allow_nested_files=allow_nested_files)
        return path
386049
def getRemoteFile(urlOrPath, destPath):
    '''
    
    '''
    urlp = urlparse(urlOrPath)
    if urlp.scheme == '':
        return (os.path.abspath(urlOrPath), 'local')
    elif urlp.scheme not in ('http', 'https'):
        return (urlOrPath, 'local')
    else:
        filename = toFilename(urlOrPath)
        destPath = destPath + '/' + filename
        log.info('Retrieving %s to %s.' % (urlOrPath, destPath))
        try:
            urlretrieve(urlOrPath, destPath)
        except IOError:
            # monkey patch fix for SSL/Windows per Tika-Python #54 
            # https://github.com/chrismattmann/tika-python/issues/54
            import ssl
            if hasattr(ssl, '_create_unverified_context'):
                ssl._create_default_https_context = ssl._create_unverified_context
            # delete whatever we had there
            if os.path.exists(destPath) and os.path.isfile(destPath):
                os.remove(destPath)
            urlretrieve(urlOrPath, destPath)
        return (destPath, 'remote')
773580
def cache_file(file_name):
	

	remote_file_path = join(join(expanduser('~'), OCTOGRID_DIRECTORY), file_name)

	try:
		copyfile(file_name, remote_file_path)
	except Exception, e:
		raise e