Send files from one remote server using JSch to another server using JSch - passwords

Please refer to an existing question regarding the same
Send files from one remote server using JSch to another server using JSch too
public boolean uploadFile() throws JSchException, SftpException {
ChannelSftp channelSftpA = createChannelSftp();
ChannelSftp channelSftpB = createChannelSftp();
channelSftpA.connect();
channelSftpB.connect();
localFilePath = "/data/upload/readme.txt";
remoteFilePath = "/bingo/pdf/";
channelSftpA.cd(localFilePath);
channelSftpA.put(localFilePath + "readme.txt", remoteFilePath + "readme.txt");
But it doesn't work. Should I put channelB.put into my first channelA.put?
Solution given for above Question is "for transferring file you should get file from server A, and that put on server B. By the way users under which you are going to download and upload files should have access to specified folders!"
private boolean transferFile() throws JSchException, SftpException {
ChannelSftp channelSftpA = createChannelSftp();
ChannelSftp channelSftpB = createChannelSftp();
channelSftpA.connect();
channelSftpB.connect();
String fileName = "readme.txt";
String remoteFilePathFrom = "/folderFrom/";
String remoteFilePathTo = "/folderTo/";
InputStream srcInputStream = channelSftpA.get(remoteFilePathFrom + fileName);
channelSftpB.put(srcInputStream, remoteFilePathTo + fileName);
System.out.println("Transfer has been completed");
channelSftpA.exit();
channelSftpB.exit();
return true;
}
But My query is
what if I want to directly transfer files from server1 to server2 without getting it on my local. This I can do using command "scp -rv /sourcefolder/text1 username#server2Hostname /destinationfolder/" but through Program it will work ONLY when public key is set up between server1 and server2 SO no Requirement to pass the password. But I need a solution when public key is Not set up and I have to use the Password, Am not able to figure out how to pass the password for server2 in this command OR if we can create parallel session/channel to server1 and server2 NOT Sure how can we do that. ANy Idea ?

Related

JDBC connection from eclipse not working, but working in Oracle SQL developer

I'm trying to connect into DB via JDBC
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:#host_name:port:service_name"; //Changed the host_name, port and service_name for confidentiality
String username = "user_name"; // Changed the user_name
String password = "my_password"; //Changed the password
Connection conn = DriverManager.getConnection(url, username, password);
Got the below exception
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
But at the same time, I could connect via Oracle SQL developer.
Note- My service_name consists of "." and "_" and My host_name contains "."
Please help here!
//Step: 1
Load Driver Class
ex- Class.forName("oracle.jdbc.driver.OracleDriver");
//Step: 2
String url="jdbc:oracle:thin:#ipaddress:portNo of oracle :database name";
ex- String url="jdbc:oracle:thin:#localhost:1521:XE";
//Step: 3
User Name
String username = "user_name";
ex- String username = "system";
//Step: 3
Password
String password = "oracle_db_Password";
ex- String password = "sys123";
//Step:4
Connection con=DriverManager.getConnection(url,username,password);
Below is the right way to create data source object from oracle documentation:
//specify the datasource object
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:#//myhost:1521/orcl");
ods.setUser("scott");
ods.setPassword("tiger");
Connection conn = ods.getConnection();
I hope you are using it right way

Automatically create new connection strings for web applications Azure

I am attempting to automate a workflow in our Azure environment.
We have several web applications with connectionstrings to several databases. Each new customer recives a new database.
I've hit a snag in the script with our connectionstrings. I want the script to update all web applications and add a new connectionstring for the newly created customer db.
The problem is "Set-Azurermwebapp -Name -ResourceGroup -ConnectionStrings" takes a hashtable which replaces any previously configured data.
I would only like to append a new connectionstring, or get the previously configered cstrings and add them to an array, then replacing all data.
Example code;
$test= #{"Type"="Custom"; "Value" = "TestValue"}
$Connectionstring=#{"test"=$test }
Set-AzureRmWebApp
-Name "testapp"
-ResourceGroupName "testgrp"
-ConnectionStrings $Connectionstring"
Any ideas here?
$connStrings = #{
AzureWebJobsDashboard = #{
Type = "Custom";
Value = $AzureWebJobsDashboard 
};
AzureWebJobsStorage = #{
Type = "MySql";
Value = $connstring
}
};
Set-AzureRMWebApp -Name $webServiceName -ResourceGroupName $rgName -ConnectionStrings $connStrings
Cannot Delete All Azure Website Connection Strings
#Add new connection string
$newConnString = New-Object Microsoft.WindowsAzure.Commands.Utilities.Websites.Services.WebEntities.ConnStringInfo
$newConnString.Name = $ConnStringName
$newConnString.ConnectionString = $ConnStringValue
$newConnString.Type = $ConnStringType
$connStrings.Add($newConnString)
Set-AzureWebsite $WebAppName -ConnectionStrings $connStrings
You can download detail script from How to automatically create new connection strings for web applications Azure

Processing-java sketch( server ) not responding in the way I want it to

I have created a processing-java sketch. This sketch is the server. All I want this program to do is that the client and server can connect and write messages(sentences) between each other. Case 1 was successful, but case 2 was not. I have explained the process for each case and what went wrong/successful.
Case 1) On the same computer(Mac), I started the server program and on Terminal("Command Prompt" on Mac), I typed telnet local host 5204 and the client(Mac) connected with the server(Mac). I was able to type sentences (or Strings) between the server and client and it was successful. So whatever sentence I type in the server, it was visible to the client and vice versa. Note: The server and client were both in the same computer.
Case 2) On the Mac, I started the server program. On another computer(Windows 7)
I connected to the server via Command Prompt. The connection was successful. In this case, the Strings could be sent from the server to the client and the Strings were visible to the client. But when I tried to send Strings to the server from the client, the server could only receive the information character by character, not as an entire sentence/String. I tried changing the port number, the client device, the frameRate, but I still had no success.
This is my problem. Please comment if my question could be clearer or if I need to give more details. Thank you for answering.
Below is my Server code:
import processing.net.*;
Server myServer;
//Strings from server and client
String typing = "";
String c = "";
void setup() {
size(400, 400);
//creating server on port 5204
myServer = new Server(this, 5204);
}
void draw() {
background(255);
//displaying server's text and client's text
fill(0);
text(typing, 100, 100);
text("Client: " + c, 100, 150);
Client client = myServer.available();
if(client != null) {
//reading input from client
c = client.readString();
c.trim();
}
}
void keyPressed() {
//Server can type sentences to client
if(key == '\n') {
myServer.write(typing + '\n');
typing = "";
}else{
typing = typing + key;
}
}
Did you try ncat for Windows?
With it you can try: echo Text to send & echo. | ncat localhost 5204
Source

How to use SqlFileStream for transactional access to SQL Server 2012 FileTable?

I'm trying to use the SqlFileStream object in a WCF service to get a handle to a specific file that is in a SQL Server 2012 FileTable. I'm able to get the path and transaction context like you would expect with no issues using this piece of code:
using (SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["FileStorage"].ConnectionString))
{
con2.Open();
string getFileHandleQuery = String.Format(
#"SELECT FileTableRootPath(), file_stream.GetFileNamespacePath(), GET_FILESTREAM_TRANSACTION_CONTEXT()
FROM {0}
WHERE stream_id = #streamId", "FSStore");
byte[] serverTransactionContext;
string serverPath;
using (SqlCommand sqlCommand = new SqlCommand(getFileHandleQuery, con2))
{
sqlCommand.Parameters.Add("#streamId", SqlDbType.UniqueIdentifier).Value = new Guid(finalFileHandleStreamId);
using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
{
sqlDataReader.Read();
serverPath = String.Concat(sqlDataReader.GetSqlString(0).Value, sqlDataReader.GetSqlString(1).Value);
serverTransactionContext = sqlDataReader.GetSqlBinary(2).Value;
sqlDataReader.Close();
}
}
con2.Close();
}
However, once I try and actually use the path and transaction context to create a new SqlFileStream:
using (SqlFileStream dest =
new SqlFileStream(serverPath, serverTxn, FileAccess.Write))
{
...
}
The above blows ups with the following exception: The mounted file system does not support extended attributes.
Can someone please explain to me what I'm doing wrong here?
Thanks!
If you are trying to use FileTable and receive an error when new a SqlFileStream object, please check the filePath value.
SqlFileStream sfs = new SqlFileStream(filePath, objContext, System.IO.FileAccess.Read); <-- Error "The mounted file system does not support extended attributes"
Correct way to obtain the filePath value is
SELECT [file_stream].PathName() FROM dbo.fTable WHERE name = 'test.xlsx'
filePath value should look like:
\\HOSTNAME\MSSQLSERVER\v02-A60EC2F8-2B24-11DF-9CC3-AF2E56D89593\test\dbo\fTable\file_stream\A654465D-1D9F-E311-B680-00155D98CA00\VolumeHint-HarddiskVolume1
not like:
\\HOSTNAME\MSSQLSERVER\Store\fDirectory\test.xlsx
That is required by design. Please refer to
https://connect.microsoft.com/SQLServer/feedback/details/729273/sql-server-denali-filetable-access-using-sqlfilestream-returns-error-the-mounted-file-system-does-not-support-extended-attributes
and
Access FILESTREAM Data with OpenSqlFilestream
http://technet.microsoft.com/en-us/library/bb933972.aspx

access Mbeans on weblogic

From the documentation of oracle :
Domain Runtime MBean Server : This MBean server also acts as a single
point of access for MBeans that reside on Managed Servers.
what i want to do is to use this fact to access all my custom mBeans scattered in several managed servers.
for example assume that i have two nodes server-1 server-2 .
how can i access all of the custom mBeans on both server-1 server-2 by connecting to the administrator node ?
i dont want to remotly access each node to return the result i want a single entry point
i managed to get the names of the servers and the states and other information by doing this
JMXConnector connector;
ObjectName service;
MBeanServerConnection connection;
String protocol = "t3";
Integer portInteger = Integer.valueOf(<admin server port>);
int port = portInteger.intValue();
String jndiroot = "/jndi/";
String mserver = "weblogic.management.mbeanservers.runtime";
JMXServiceURL serviceURL = new JMXServiceURL(protocol, "<serverName>", port,
jndiroot + mserver);
Hashtable h = new Hashtable();
h.put(Context.SECURITY_PRINCIPAL, "weblogic");
h.put(Context.SECURITY_CREDENTIALS, "weblogicpass");
h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,
"weblogic.management.remote");
h.put("jmx.remote.x.request.waiting.timeout", new Long(10000));
connector = JMXConnectorFactory.connect(serviceURL, h);
connection = connector.getMBeanServerConnection(); service = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
ObjectName[] ons = (ObjectName[]) connection.getAttribute(service, "ServerRuntimes");
int length = (int) ons.length;
for (int i = 0; i < length; i++) {
String name = (String) connection.getAttribute(ons[i],
"Name");
String state = (String) connection.getAttribute(ons[i],
"State");
String internalPort = (String) connection.getAttribute(ons[i],"ListenPort");
System.out.println("Server name: " + name + ". Server state: "
+ state);
but i need to access the custom Mbeans created on each server and not only the information
maybe my question wasnt clear but i found an answer and i will share it here now :
Question summary : i need to access custom mBeans exists in a managed server by connecting to the administration server from a client application.
Answer :
to do that you need to deploy your application to the administrator server (i tried remote but it didn't work )
you need to connect to the DomainRuntimeServiceMBean because it provide a common access point for navigating to all runtime and configuration MBeans in the domain .
when searching for the Object name add Location=
here is the code:
Hashtable props = new Hashtable();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
props.put(Context.SECURITY_PRINCIPAL, "<userName>");
props.put(Context.SECURITY_CREDENTIALS, "<password>");
Context ctx = new InitialContext(props);
MBeanServer server = (MBeanServer)ctx.lookup("java:comp/env/jmx/domainRuntime");
ObjectName on =new ObjectName("com.<companyName>:Name=<Name>,Type=<Type>,Location=<managed_server_name>");
boolean boolresult=(Boolean)server.invoke(on, "<method_Name>",
new Object[]{"<ARG1>","<ARG2>","<ARG3>"}
,new String[]{"java.lang.String","java.lang.String","java.lang.String"});
out.print(boolresult);