You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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;
}
The text was updated successfully, but these errors were encountered:
Unlike earlier version of Ganymed, the SCPClient.put() method now returns an SCPOutputStream object. You are responsible for copying the file contents yourself. Something like this:
out=client.put(myFile, new File(myFile).length(), "/tmp", "0777");
in = new FileInputStream(new File(src))
IOUtils.copy(in, out)
in.close()
out.close()
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.
The text was updated successfully, but these errors were encountered: