0

I have to copy the log files from unix server. in putty after login, I have to run sudo su -o oper command. once sudo code executed.. move to the logs folder using cdlog command then downloads the files from the directory.

Current code:

JSch conn = new JSch();
        Session session = null;
        session = conn.getSession(username, server, port);
        session.setPassword(password);
        session.setConfig("StrictHostKeyChecking", "no");
        session.connect();
        Channel sftp = session.openChannel("exec");
        ((ChannelExec) sftp).setCommand("sudo su - oper");

        ((ChannelExec) sftp).setCommand("cdlog");
        ((ChannelExec) sftp).setCommand("ls");
        sftp.connect();

After moved to the cdlogs folder, how to download the files?

if i use session.openChannel("sftp") then pwd is showing the path before sudo command was executed.

How to execute the sudo command and download the file with same session?

Thanks in advance.

  • *if i use session.openChannel("sftp") then pwd is showing the path before sudo command was executed.* Why is that a problem? You might download with `rsync`. – g00se Jul 01 '23 at 09:44

0 Answers0