0
So, I made a program in Java using Netbeans to upload an "X" file to an SFTP server and the method is functional, but once I start the program, it just shuts down, I’ve tried several things but nd solved my problem. My code is:
public void Upload(String localfile) {
String SFTPHOST = "example.com";
int SFTPPORT = 22;
String SFTPUSER = "user";
String SFTPPASS = "pass";
String SFTPWORKINGDIR = "/var/";
Session session = null;
Channel channel = null;
ChannelSftp channelSftp = null;
try {
JSch jsch = new JSch();
session = jsch.getSession(SFTPUSER, SFTPHOST, SFTPPORT);
session.setPassword(SFTPPASS);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
channel = session.openChannel("sftp");
channel.connect();
channelSftp = (ChannelSftp) channel;
channelSftp.cd(SFTPWORKINGDIR);
File f = new File(localfile);
channelSftp.put(new FileInputStream(f), f.getName());
channelSftp.disconnect();
} catch (Exception ex) {
ex.printStackTrace();
}
}
What library are you using? Where are the classes
JSch
,Session
,Channel
andChannelSftp
?– Victor Stafusa
Ah, I’ve got it: http://www.jcraft.com/jsch/
– Victor Stafusa