I have problem with short script JSCH which I'm using ind Oracle Data Integrator. I want to send file from directory to server SFTP. My code:
import com.jcraft.jsch.*;
JSch ssh = new JSch();
Session session = ssh.getSession("pas", "host", 22);
session.setConfig("StrictHostKeyChecking", "no");
session.setConfig(
"PreferredAuthentications",
"publickey,keyboard-interactive,password");
session.setPassword("pass");
session.connect();
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftp = (ChannelSftp) channel;
sftp.put("C:\Tools\tmp.html", "/var/temp/temp.html");
channel.disconnect();
session.disconnect();
I get error:
ODI-1590: The execution of the script failed.
Caused By: org.apache.bsf.BSFException: BeanShell script error: Sourced file:
inline evaluation of: ``
import oracle.odi.km.exception.OdiKMException;
import com.jcraft.jsch.*;
J . . . '' Token Parsing Error: Lexical error at line 23, column 19.
Encountered: "W" (87), after : "\"C:\\": <at unknown location>
BSF info: upload file at line: 0 column: columnNo
What I'm doing wrong?
You have to escape the backslashes in your local path String
:
sftp.put("C:\\Tools\\tmp.html", "/var/temp/temp.html");
That's because a backslash itself escapes the next character and if you put single backslashes in "C:\Tools\tmp.html"
, the result would be (but isn't) something like "C:oolsmp.html"
, which is unlikely to be considered a valid path.
In my IDE (eclipse), a String
with single backslashes is considered a compilation error, the code doesn't even compile.
The error is this:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )