int128 / gradle-ssh-plugin

Gradle SSH Plugin
https://gradle-ssh-plugin.github.io
Apache License 2.0
318 stars 60 forks source link

'get from' copy task not respecting directory hierarchy with Gradle 5.1 #321

Open riterdando opened 5 years ago

riterdando commented 5 years ago

Hi,

I am using your ssh plugin since quite a while and I really like it. But with Gradle 5.1 I see a problem, when using the get from copy task to retrieve a whole directory structure from the remote host. All files and directories are copied, but the directory structure is lost, so all files are copied to the top level of the target directory and all the subdirectories from the remote host are copied here too, but they are empty. More information below. Please note that using the same build with Gradle 4.10.2 does not lead to the described problem.

Can you have a look and provide a fix for the problem?

Environment info

gradle-ssh-plugin-2.9.0 (groovy-ssh-2.9.0, jsch-0.1.53, groovy-2.5.4, java-1.8.0_191)

Steps to reproduce

  1. Create a simple build file, containing the snippets shown below, including the doCopy task.

  2. When using the doCopy task the contents of the remote folder should be copied to the build directory on the local host, including the directory hierarchy. But the hierarchy is lost. The build directory contains just all files and empty directories from the target host.

ssh.settings {
        fileTransfer = 'scp'
        jschLog = true
        logging = 'stdout'
}
remotes {
        bla {
                host = "targethost"
                user = "targetuser"
                identity = file("${System.getProperty('user.home')}/.ssh/id_rsa")
        }
}
task doCopy {
        doLast 
                file("${buildDir}").mkdirs()
                ssh.run {
                        session(remotes['bla']) 
                                get from: '/home/targetuser/integrationtest', into: "${buildDir}/"
                        }
                }
        }
}
manticore-projects commented 1 year ago

Greetings. I have used successfully the snippet below to work around:

    doLast {
        ssh.run {
            session(remotes.webServer) {
                for (File file: fileTree(include:['*.jar'], dir:"./sourceDirrectory").collect()) {
                    put from: file, into: "download/targetDirectory"
                }
            }
        }
    }