Question

I am attempting to upload a file to an SFTP site, but the entire directory structure is being recreated on the SFTP site instead of just uploading the file at the root. I am calling sendSftp (see below).

public void sendSftp(String filename, IPropertyHelper ph) {
    def local = VFS.getManager().toFileObject(new File("${filename}"))
    def remote = VFS.getManager().resolveFile(buildSftpPath(filename, ph), new FileSystemOptions());
    remote.copyFrom(local, Selectors.SELECT_SELF) 
}

private String buildSftpPath(filename, IPropertyHelper ph) {
    return "sftp://${ph.properties.sftp_Login}:${ph.properties.sftp_Password}@${ph.properties.sftp_Hostname}/${filename}"
}

Any help in how to send just the file and place it at the root of the SFTP site would be great, thanks!

Was it helpful?

Solution

What is filename? I suspect buildSftpPath(filename, ph) is building the full directory structure... Try buildSftpPath(new File( filename ).name, ph)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top