I am trying to connect to a SFTP remote server using JSCH library version 0.1.49. Every time I run the program I receive the following error :
Initializing...
Connection to SFTP server is successfully
com.jcraft.jsch.JSchException: Unable to connect to SFTP server.com.jcraft.jsch.JSchException: failed to send channel request
at shell.MainClass.JschConnect(MainClass.java:95)
at shell.MainClass.main(MainClass.java:30)
line 30 is : sftpChannel.connect() from the code below :
System.out.println("Initializing...");
JSch jsch = new JSch();
Session session = null;
try {
session = jsch.getSession(ProjectConstants.rmUsername,ProjectConstants.rmHost, 22);
session.setPassword(ProjectConstants.rmPassword);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
if (session.isConnected() == true) {
System.out.println("Connection to SFTP server is successfully");
}
ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
try {
sftpChannel.connect();
} catch (Exception e) {
throw new JSchException("Unable to connect to SFTP server. "
+ e.toString());
}
the credentials I am using are correct ( it connects through FileZilla using the same data ), and I also disabled the proxy for that server ( either way I get the same error with or without proxy )
If anyone could help me I would greatly appreciate it as I am stuck with this error for about a week now ...
Thank you.
Check if SFTP server is started and running.
I had encountered the same issue - I was not able to open SFTP channel to my server, but I could connect with WinSCP. It took me some time to notice that WinSCP would fallback to SCP hence confusing me. Starting the server solved this issue.
Check Subsystem sftp /usr/lib/openssh/sftp-server in /etc/ssh/sshd_config
In /etc/ssh/sshd_config I changed:
Subsystem sftp /usr/lib/openssh/sftp-server
to:
Subsystem sftp internal-sftp
It helps.
Related
I am writing a grpc based server and client. Server is running on linux and client is running on windows.
I am trying to handle the scenario when the server is not started but the client is up.
auto state = m_channel->GetState(true);
while (state != GRPC_CHANNEL_READY || state != GRPC_CHANNEL_SHUTDOWN)
{
std::chrono::time_point deadline = std::chrono::system_clock::now() + std::chrono::seconds(30);
if (m_channel->WaitForStateChange(state, deadline))
{
std::cout << "new state is: " << static_cast<int>(state) << "\n";
state = m_channel->GetState(true);
}
}
When I run, this it fails with this error:
**
I0929 22:24:05.748000000 14812 subchannel.cc:905] subchannel 0123CF78 {address=ipv4:192.168.175.130:40051, args={grpc.client_channel_factory=0x121dd68, grpc.default_authority=192.168.175.130:40051, grpc.internal.channel_credentials=0x121dce8, grpc.internal.security_connector=0x1235f28, grpc.internal.subchannel_pool=0x1225db0, grpc.max_receive_message_length=-1, grpc.primary_user_agent=grpc-c++/1.49.0-dev, grpc.resource_quota=0x1225990, grpc.server_uri=dns:///192.168.175.130:40051}}: connect failed (UNAVAILABLE:WSA Error {syscall:"ConnectEx", os_error:"No connection could be made because the target machine actively refused it.\r\n", grpc_status:14, wsa_error:10061, created_time:"2022-09-29T20:24:05.748604482+00:00"}), backing off for -1057 ms
**
Where as when I run the client on linux, I see it properly waiting till the server is up and running.
Is there a specific firewall setting that is needed for windows ?
Interesting thing to notice is the back off time is in -ve, where as on linux, it is a +ve value and increases as per the backoff strategy.
The issue is fixed, when I started using grpc conan-package to build the server and client instead of locally built grpc from source. I believe some mistakes were made while building grpc locally from source.
I did not get time to look in details for the root cause it.
I am running into
Error: could not receive data from server: Software caused connection abort (0x00002745/10053)
upon trying to connect to a postgres database using the DBI package in R. Note that i am in a work environment, so subject to a corporate firewall. Can that explain the error or is there something else that could be happening?
Here is the code I'm using
# Connect to trayaway dev
con <- DBI::dbConnect(
RPostgres::Postgres(),
host = host, port = 5432, dbname = "postgres",
user = user, password = password
)
error below:
Error: could not receive data from server: Software caused connection abort (0x00002745/10053)
solution was found- i tried the same code using wiFi and the code works - when hardwired, connection string fails to connect to database - so this is a corporate firewall issue - thank you,
I make a server and request successfully in windows,then I put them to the linux which is the develop machine of company.
And I Got Connect Failed error when I run the clien.py. I have changed the host IP to localhost,0.0.0.0,127.0.0.1 and the IP of develop machine,but it doesn't work.
And I tried the docker inspect command,but the IPAddress is empty like "".
And I changed the port to 8500,8501,4321 and still got the error.
I tried make proxy to the company,the request returns a Name resolution failure error.So I think maybe the cause is the net of company?
Any answer would be very appreciate!
The Error Message:
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "Connect Failed"
debug_error_string = "{"created":"#1551677753.381330483","description":"Failed to create subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":2721,"referenced_errors":[{"created":"#1551677753.381328206","description":"Pick Cancelled","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":241,"referenced_errors":[{"created":"#1551677753.381303114","description":"Connect Failed","file":"src/core/ext/filters/client_channel/subchannel.cc","file_line":689,"grpc_status":14,"referenced_errors":[{"created":"#1551677753.381278484","description":"Failed to connect to remote host: OS Error","errno":111,"file":"src/core/lib/iomgr/tcp_client_posix.cc","file_line":205,"os_error":"Connection refused","syscall":"connect","target_address":"ipv4:0.0.0.0:8501"}]}]}]}"
I'm getting the following error installing drupal 7:
Failed to connect to your database server. The server reports the following message: SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'myservername' (13).
I am running MySQL on one windows server and httpd on another linux. MySQL is running just fine and on the httpd server I can connect just fine to the MySQL, as follows:
mysql -h dbserver -p --port=3001 -u drupal
Similarly I can run mysqli and pdo and it connection just fine too from my httpd:
<?php
$servername = "dbserver";
$username = "drupal";
$password = "xxx";
$dbname = "drupal";
$port = 3001;
$conn = new mysqli($servername, $username, $password, $dbname, $port);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$conn->close();
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname;port=$port", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
$conn=null;
?>
So there is nothing wrong on my web server or php or mysql. It's just through the installation that it fails. I've been in the advanced and entered all the correct details.
Any idea? I looked and there was no apache log and I couldn't figure out how to increase error reporting during install or find exactly where it does the database connection check..
thanks.
Can you confirm you have dbserver's ip mapped.
Go to terminal and type : "ping dbserver" and please post result.
EDITED: This situation was caused by a security policy of the linux distro where the apache server is setup that doesn't allow it to connect to remote mysql instances. For solving this situation go to terminal and type sudo setenforce 0, that way linux won't enforce such strict webserver behaviour.
Assuming you're using RHEL/CentOS, I found the answer from #alexbilbie here:
setsebool -P httpd_can_network_connect_db 1
From the RHEL documentation:
When disabled, this Boolean prevents HTTP scripts and modules from initiating a connection to database servers. Enable this Boolean to allow this access.
I am trying to use Jsch Sftp Channel to upload a file to an IBM Mainframe, and the directory has to be "//", where the mainframe will automatically route the file where it needs to go.
In an sftp command session on the IBM mainframe, I can do this:
sftp myuser#1.2.3.4
connecting to 1.2.3.4...
myuser#1.2.3.4's password:
sftp> pwd
Remote working directory: /users/home/myuser
sftp> cd //
sftp> pwd
Remote working directory: //
sftp> put "#12345.abcdef.xxx.xxx"
uploading #12345.abcdef.xxx.xxx to //#12345.abcdef.xxx.xxx
#12345.abcdef.xxx.xxx 100% 403 0.4KB/s 00:00
So I created a JSch sftp session (version 0.1.5.1) to attempt the same upload, but it does not work:
JSch jsch = new JSch();
Session session = jsch.getSession("myuser", "1.2.3.4");
session.setPassword("mypass");
session.connect();
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftp = (ChannelSftp)channel;
log.info(" user home pwd " + sftp.pwd()); //prints /users/home/myuser
sftp.cd("//")
log.info(" pwd after cd " + sftp.pwd()); //only prints /
sftp.put(filename); //get sftp error, no such file
So I cannot get to that // structure through the JSch library. Is there a certain mode or flag that needs to be set for the sftp session to know it's on a mainframe?
I have no issue at all doing a JSch sftp session to my /users/home/myuser directory, just can't get it to go to the //
I had a similar issue with pseudofolder "//".
Avoid this sftp.cd("//") and better try this sftp.put("/-/"+filename); instead, that solved my problem. Hopefully will help you as well.
Try it without calling ChannelSftp.cd():
ChannelSftp sftp = (ChannelSftp)channel;
sftp.put("//" + filename); // Put to //#12345.abcdef.xxx.xxx
The SFTP protocol doesn't actually have a chdir-type operation. At the protocol level, pathnames which don't start with "/" are always interpreted relative to the directory where the SFTP session started. There's no protocol command to change that starting directory.
SFTP clients, including Jsch, emulate chdir-like behavior client-side. When you call ChannelSftp.cd(), Jsch stores the new remote directory locally. When you later call put() or get(), and give a pathname that doesn't start with "/", Jsch prepends the remote directory onto the filename and passes the altered name to the remote server.
I think what's happening to you is that Jsch's chdir emulation is being a little too clever. When you call cd("//"), it's collapsing the "//" into a single "/" and storing that. Then you call put() for a relative pathname, it's prepending the single "/" instead of the double "//" that you want.
Based on inspecting the Jsch source code, it looks like Jsch never alters remote names that start with "/". If you call put("//somefile"), Jsch should use the name you specified as-is.