mirror of
				https://github.com/ARM-software/devlib.git
				synced 2025-11-04 07:51:21 +00:00 
			
		
		
		
	utils/ssh: Allow SSH to use SCP as a file transfer method
Paramiko uses sftp for file transfer rather then scp as with the previous implementation however not all targets support this. Expose a parameter to the SSHConnection to allow falling back to the scp implementation.
This commit is contained in:
		@@ -359,6 +359,7 @@ class SshConnection(SshConnectionBase):
 | 
			
		||||
                 platform=None,
 | 
			
		||||
                 sudo_cmd="sudo -S -- sh -c {}",
 | 
			
		||||
                 strict_host_check=True,
 | 
			
		||||
                 use_scp=False
 | 
			
		||||
                 ):
 | 
			
		||||
 | 
			
		||||
        super().__init__(
 | 
			
		||||
@@ -373,6 +374,15 @@ class SshConnection(SshConnectionBase):
 | 
			
		||||
        )
 | 
			
		||||
        self.timeout = timeout if timeout is not None else self.default_timeout
 | 
			
		||||
 | 
			
		||||
        # Allow using scp for file transfer if sftp is not supported
 | 
			
		||||
        self.use_scp = use_scp
 | 
			
		||||
        if self.use_scp:
 | 
			
		||||
            logger.debug('Using SCP for file transfer')
 | 
			
		||||
            _check_env()
 | 
			
		||||
            self.options = self._get_default_options()
 | 
			
		||||
        else:
 | 
			
		||||
            logger.debug('Using SFTP for file transfer')
 | 
			
		||||
 | 
			
		||||
        self.client = self._make_client()
 | 
			
		||||
        atexit.register(self.close)
 | 
			
		||||
 | 
			
		||||
@@ -522,10 +532,18 @@ class SshConnection(SshConnectionBase):
 | 
			
		||||
            cls._pull_folder(sftp, src, dst)
 | 
			
		||||
 | 
			
		||||
    def push(self, source, dest, timeout=30):
 | 
			
		||||
        # If using scp, use implementation from base class
 | 
			
		||||
        if self.use_scp:
 | 
			
		||||
            super().push(source, dest, timeout)
 | 
			
		||||
        else:
 | 
			
		||||
            with _handle_paramiko_exceptions(), self._get_sftp(timeout) as sftp:
 | 
			
		||||
                self._push_path(sftp, source, dest)
 | 
			
		||||
 | 
			
		||||
    def pull(self, source, dest, timeout=30):
 | 
			
		||||
        # If using scp, use implementation from base class
 | 
			
		||||
        if self.use_scp:
 | 
			
		||||
            super().pull(source, dest, timeout)
 | 
			
		||||
        else:
 | 
			
		||||
            with _handle_paramiko_exceptions(), self._get_sftp(timeout) as sftp:
 | 
			
		||||
                self._pull_path(sftp, source, dest)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user