Braiam Thushi Thushi 8, 4 4 gold badges 22 22 silver badges 41 41 bronze badges. You could just use public key authentication for your SSH connections. See for example stackoverflow. No,I can't do that. Bcos I would like to automate it. And I need some way to copy the public key to remote system without user intervention,I mean through java code. Asking the password for very first time is fine. But it should not ask every time I run the code. Yeah Thank you.
I implemented this using Jsch library with sftp channel. And for the very first time I'll be having the credentials of the remote system so I don't have any issues in login. And then as suggested by SamiLaine I copied my public key and my actual files the files which I actually wanted to copy to remote system. So for the next time while copying it didn't asked for any password.
Add a comment. Also Add this JAR in your project. I looked at a lot of these solutions and didn't like many of them. Mostly because the annoying step of having to identify your known hosts. That and JSCH is at a ridiculously low level relative to the scp command. I found a library that doesn't require this but it's bundled up and used as a command line tool. I looked through the source code and discovered how to use it without the command line.
Here's an example of uploading:. The biggest downside is that it's not in a maven repo that I could find. But, the ease of use is worth it to me. Here is an example to upload a file using JSch :. Below is an example of a method that will connect to sftp server and download files to specified directory.
It is recommended to stay away from disabling StrictHostKeyChecking. Although a little bit more difficult to set up, for security reasons specifying the known hosts should be the norm. Add this dependency in your project. Latest version can be found here. I wrote an scp server which is much easier than others. How to use? Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 13 years, 3 months ago. Active 1 year, 8 months ago. Viewed k times. Improve this question. Lloyd Meinholz Lloyd Meinholz 2, 1 1 gold badge 22 22 silver badges 20 20 bronze badges. Add a comment. Active Oldest Votes. Post as a guest Name.
Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Related Hot Network Questions. I used to create those files manually: Open the WinSCP, give the credentials, open the desired path and upload the file.
Now I am in a situation to automate those things. Text will be entered in a text box or fetched from DB, it has to be written in a notepad file and should be uploaded to a WinSCP path.
I have implemented writing the file and it is working fine. What you call "WinSCP path" is actually a storage accessible via some file transfer protocol. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 7 years, 7 months ago.
0コメント