I'm trying to retrieve a file from a server using SFTP (as opposed to FTPS) using Java. How can I do this?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Andy, to delete file on remote system you need to use
(channelExec)
of JSch and pass unix/linux commands to delete it.You also have JFileUpload with SFTP add-on (Java too): http://www.jfileupload.com/products/sftp/index.html
Below is an example using Apache Common VFS:
The best solution I've found is Paramiko. There's a Java version.
Common java properties file for all the examples
serverAddress=111.222.333.444
userId=myUserId
password=myPassword
remoteDirectory=products/
localDirectory=import/
There is a nice comparison of the 3 mature Java libraries for SFTP: Commons VFS, SSHJ and JSch
To sum up SSHJ has the clearest API and it's the best out of them if you don't need other storages support provided by Commons VFS.
Here is edited SSHJ example from github: