SSH & SFTP

This guide provides detailed, step-by-step instructions for configuring and executing the sample jobs located in the SSH and SFTP examples folder. These examples showcase the powerful capabilities of Snoweaver in performing various remote operations, including:

  1. Executing remote shell commands via SSH

  2. Conducting secure file transfer operations using SFTP

Prerequisites

Before continuing with this guide, ensure you have completed the following prerequisites:

  • Install the Snoweaver CLI.

  • If you have just installed Snoweaver, ensure you have launched the admin console to initialize the Admin API.

Preparation

  1. Donwlaod or Clone the Quickstart Repository to your local machine.

  2. Navigate to the directory examples/ssh_sftp

  3. Open the setup.sh file in a text editor to update the following variables, or alternatively, set their values using environment variables:

    • CONN Specify the Snowsql connection for the Snowflake account, ensuring it points to database: SNOWEAVER and schema: LEARN_DEV. Verify that the role associated with this connection has the required privileges to execute the commands in setup.sql. Ideally, use the AccountAdmin role or an equivalent role in a sandbox environment.

    • USER The Snowflake user defined in the Snowsql connection.

    • SSH_SERVER The hostname or IP address of the SSH server to which the example will connect.

    • SSH_PORT The port number on which the SSH server is listening (default is usually 22).

    • SSH_USER The username for authenticating the SSH connection.

    • SSH_PRIVATE_KEY The private key used for SSH authentication. Specify it in the following format:

      SSH_PRIVATE_KEY="
      -----BEGIN PRIVATE KEY-----
      b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2gtcn
      NhAAAAAwEAAQAAAQEAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      -----END PRIVATE KEY-----
      "
      

      Note

      Replace the ‘x’ characters with your actual private key content.

    • SSH_PRIVATE_KEY_PASSPHRASE The passphrase used to encrypt the SSH private key.

Set up the sample project

  1. On your client machine, open a command-line terminal (Linux, macOS) or Git Bash (Windows) and navigate to the same directory.

  2. Execute the following command to set up the example project:

    bash setup.sh
    

    Note

    If the LEARN_DEV project already exists, all its resources will be deleted, with the exception of the DATA stage and the RESULTS table.

    To retain your data, you can remove the -d flag from the ‘sw import all -c ${CONN} -d’’ command in the setup.sh script.

    Alternatively, use the Snoweaver CLI to create a backup of the project’s contents.

  3. After the execution completes, you can access the sample jobs in the LEARN_DEV project.

Sample Jobs

ssh_exec_cmd

This job demonstrates how to execute a command on a remote server via a secure shell (SSH) connection. It showcases the ability to run shell commands securely on a remote system, which can be useful for various administrative tasks or data processing operations.

sftp_upload

This job illustrates the process of uploading a file to a remote server using the SFTP protocol. It demonstrates how to securely transfer files from your local Snowflake environment to a remote server, which is essential for data distribution or backup purposes.

sftp_download

This job showcases the functionality of downloading a file from a remote server using the SFTP protocol. It exemplifies how to securely retrieve files from a remote system to your Snowflake environment, which is crucial for data ingestion or synchronization tasks.