Retrieving data from an SFTP server using JSch

前端 未结 3 630
孤城傲影
孤城傲影 2021-02-14 17:12

I am using JSch for retrieving a file from a remote machine by SFTP. Here is the code

public class TestSFTPinJava {

 public static void main(String args[]) {
           


        
3条回答
  •  悲哀的现实
    2021-02-14 17:55

    Concerning your point 1, I suspect that the default directory after connecting is not what you expect. Try using an absolute remote path. Does sftpChannel.pwd() return the directory the file remote-data.txt is in on the remote machine ?

    Concerning your point 2, looking at http://grepcode.com/file/repo1.maven.org/maven2/com.jcraft/jsch/0.1.42/com/jcraft/jsch/ChannelSftp.java#290 one sees that there is the following method in ChannelSftp:

     public void put(String src, String dst)
    

    which indeed has a source and destination file name argument.

    I guess you had already a look the Jsch sftp example at http://www.jcraft.com/jsch/examples/Sftp.java ?

提交回复
热议问题