In Jenkins pipeline, you can use the sshPut step to copy the contents of a folder instead of the folder itself. The sshPut step is used to copy files or directories to a remote server over SSH.

To copy the contents of a folder, you should use the ${WORKSPACE} variable along with a wildcard () to specify the contents of the folder. The ${WORKSPACE} variable represents the current workspace directory in Jenkins, and the wildcard () allows you to select all the files and subdirectories within the specified folder.

Here's an example of how you can use sshPut in a Jenkins pipeline to copy the contents of a folder:

pipeline {
    agent any

    stages {
        stage('Copy Contents via SSH') {
            steps {
                script {
                    // Define SSH credentials
                    def sshCredentials = credentials('ssh-cred-id')

                    // Define the remote server details
                    def remoteServer = [
                        host: 'www.example.com',
                        port: 22,
                        user: 'testuser1',
                        password: sshCredentials(password: true)
                    ]

                    // Source folder in the Jenkins workspace
                    def sourceFolder = "${WORKSPACE}/path/to/test1/*"

                    // Destination folder on the remote server
                    def destinationFolder = "/path/to/test2/"

                    // Copy the contents of the source folder to the remote server
                    sshPut remote: remoteServer, from: sourceFolder, into: destinationFolder
                }
            }
        }
    }
}


Make sure to replace the placeholders:

1. ssh-cred-id: The ID of the SSH credentials added in Jenkins (Jenkins > Credentials > System > Global credentials).

2. www.example.com: The hostname or IP address of the remote server you want to copy the files to.

3. testuser1: The username to log in to the remote server.

4. /path/to/test1/*: The path to the source folder whose contents you want to copy. Use * as a wildcard to select all files and subdirectories in that folder.

5. /path/to/test2/: The path to the destination folder on the remote server where you want to copy the files.

Remember to have proper permissions and access rights on the remote server for the user you are using to connect via SSH. Additionally, ensure that the necessary SSH keys and configurations are set up correctly for passwordless authentication, if applicable.