Java – use jsch to put files into a remote directory and create it if it does not exist
•
Java
I want to copy files to a remote directory using the jsch library and the SFTP protocol
In the API documentation, http://epaul.github.com/jsch-documentation/javadoc/ , I noticed that the put method has a "mode", but it is only one of the transfer modes: – transfer mode, resume, append, overwrite
Is there a simple way to do this without having to write your own code to check for existence and then create a directory recursively?
Solution
As far as I know, I use the following code to do the same thing:
String[] folders = path.split( "/" ); for ( String folder : folders ) { if ( folder.length() > 0 ) { try { sftp.cd( folder ); } catch ( SftpException e ) { sftp.mkdir( folder ); sftp.cd( folder ); } } }
Where SFTP is the channelsftp object
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码