sshj
sshj copied to clipboard
Switching user before SCP file transfer
trafficstars
Hello Jeroen!
I'm trying to implement scenario:
- It needs to download a file from remote host via SCP
- To get access to it, I need to connect to remote host under user A, then switch to user B like "sudo su - B", for user A has no permission to read a file I need and user B has no permission to connect to that remote host.
It looks like a quite common case, but I can't make it working with SSHJ for I don't see an opportunity to call "sudo su - B" in SCPEngine before a file transfer starts.
I was trying to switch user for a Session before SCPEngine is created, but it always leads to "net.schmizz.sshj.common.SSHRuntimeException: This session channel is all used up" for session is not allowed to be reused.
I hope there is a way to do this trick, could you please advise?
+1
You could take a look at how this is implemented in Overthere (https://github.com/xebialabs/overthere).