-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
I want to upload file from windows to Unix. File created, but it's empty.
This code creates empty 'C:\Users\myuser\test\mydir\my_test_file.sql' file in /tmp directory insted of my_test_file.sql.
Tried to move "my_test_file.sql" to working dir to use file without full path, but it creates empty "my_test_file.sql" file.
There is no any error message.
Tried for both 262 and 263 versions.
Note: At the end need to use 263 version to include key-exchange algorithms related changes.
public void test() {
String hostName = "my-IP";
String userName = "user";
String password = "pass";
try {
Connection conn = getSSHConnection(hostName, userName, password);
String myFile = "C:\\Users\\myuser\\test\\mydir\\my_test_file.sql";
SCPClient client = conn.createSCPClient();
client.put(myFile, new File(myFile).length(), "/tmp", "0777");
} catch (Exception e) {
System.out.println("ERROR: " + e.getMessage());
}
}
Connection getSSHConnection(String hostName, String userName, final String password) throws IOException, Exception {
Connection conn = new Connection(hostName);
conn.connect();
String[] strArray;
try {
strArray = conn.getRemainingAuthMethods(userName);
} catch (IOException var7) {
throw new Exception("Getting Remaining AuthMethods failed with IOException: " + var7.getMessage());
}
if (strArray == null) {
System.out.println("conn.getRemainingAuthMethods returns null");
try {
conn.authenticateWithPassword(userName, password);
} catch (Exception var8) {
String warning = "";
if (password.equals("")) {
warning = warning + " : Warning: Implementation of this package does not allow empty passwords for authentication";
}
throw new Exception("Authentication with password failed: " + var8.getMessage() + warning);
}
} else {
List<String> authMethods = Arrays.asList(strArray);
if (authMethods.contains("password")) {
if (!conn.authenticateWithPassword(userName, password)) {
throw new Exception("Password based authentication failed.");
}
} else {
if (!authMethods.contains("keyboard-interactive")) {
throw new Exception("SSH Server doesnt support password or keyboard-interactive logins");
}
InteractiveCallback cb = new InteractiveCallback() {
public String[] replyToChallenge(String name, String instruction, int numPrompts, String[] prompt, boolean[] echo) throws Exception {
String[] response = new String[numPrompts];
for (int i = 0; i < response.length; ++i) {
response[i] = password;
}
return response;
}
};
if (!conn.authenticateWithKeyboardInteractive(userName, cb)) {
throw new Exception("Keyboard-interactive based authentication failed.");
}
}
}
return conn;
}
Metadata
Metadata
Assignees
Labels
No labels