package bridge

import (
	
	
	
	

	
	
	
)

// OpenSFTPConnection creates a new SFTP connection
func ( *ssh.Client) *sftp.Client {
	,  := sftp.NewClient()
	if  != nil {
		logger.Sugar().Errorw("cannot initialize sftp client", "details", )
	}

	return 
}

// SftpPutFile uploads file on remote path
func ( *Session) (,  string) error {
	if .SSH != nil {
		.SFTP = OpenSFTPConnection(.SSH)
	} else {
		return errors.New("sftp connection is not alive")
	}

	 := .SFTP

	 := .SFTP.Walk(filepath.Dir())
	for .Step() {
		if .Err() != nil {
			continue
		}
	}

	,  := .Create()
	if  != nil {
		return 
	}
	defer .Close()

	,  := os.Open()
	if  != nil {
		return 
	}
	defer .Close()

	_,  = io.Copy(, )
	if  != nil {
		return 
	}

	return nil
}

// SftpGetFile downloads file from remote path
func ( *Session) (,  string) error {
	if .SSH != nil {
		.SFTP = OpenSFTPConnection(.SSH)
	} else {
		return errors.New("sftp connection is not alive")
	}

	 := .SFTP

	 := .Walk(filepath.Dir())
	for .Step() {
		if .Err() != nil {
			continue
		}
	}

	,  := .Open()
	if  != nil {
		return 
	}
	defer .Close()

	_,  = os.Stat()
	if os.IsNotExist() {
		_,  = os.Create()
		if  != nil {
			return 
		}
	}

	,  := os.OpenFile(, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
	if  != nil {
		return 
	}
	defer .Close()

	_,  = io.Copy(, )
	if  != nil {
		return 
	}

	return nil
}