code: def get_sftp_conn(config):
      
      remote = config.get('remote_location')
      parts = urlparse(remote)
  
      if ':' in parts.netloc:
          hostname, port = parts.netloc.split(':')
      else:
          hostname = parts.netloc
          port = 22
      port = int(port)
  
      username = config.get('remote_username') or getuser()
      luser = get_local_user(username)
      sshdir = get_ssh_dir(config, luser)
      hostkey = get_host_keys(hostname, sshdir)
  
      try:
          sftp = None
          keys = get_ssh_keys(sshdir)
          transport = Transport((hostname, port))
          while not keys.empty():
              try:
                  key = PKey.from_private_key_file(keys.get())
                  transport.connect(
                      hostkey=hostkey,
                      username=username,
                      password=None,
                      pkey=key)
                  sftp = SFTPClient.from_transport(transport)
                  break
              except (PasswordRequiredException, SSHException):
                  pass
          if sftp is None:
              raise SaChannelUpdateTransportError("SFTP connection failed")
          return sftp, transport
      except BaseException as msg:
          raise SaChannelUpdateTransportError(msg)
docs: Make a SFTP connection, returns sftp client and connection objects