2016-11-22 58 views
1

我想顯示文件從Windows到java。我將ssh配置爲我的窗口,並嘗試獲取文件,我可以用從Windows獲取文件從ssh服務器從java

CD /程序文件(x86)/ syslogd的/日誌

TYPE SyslogCatchAll-2016-11-22.txt

讀取膩子文件
public static void main(String[] args) throws JSchException,IOException,SftpException { 



      JSch jsch = new JSch(); 
      Session s; 
      s = jsch.getSession("host", "192.168.1.2", 22); 

      s.setConfig("StrictHostKeyChecking", "no"); 
      s.setPassword("host"); 
      s.connect(); 


      ChannelSftp sftpChannel = (ChannelSftp) s.openChannel("sftp"); 
      sftpChannel.connect(); 
      System.out.println("SFTP Channel created."); 
      InputStream out= null; 
      sftpChannel.cd("C:\\Program Files (x86)\\Syslogd\\Logs"); 
      sftpChannel.get("SyslogCatchAll-2016-11-22.txt"); 
      BufferedReader br = new BufferedReader(new InputStreamReader(out)); 
      String line; 
      while ((line = br.readLine()) != null) 
     { 
      System.out.println(line); 
      } 
      br.close(); 
     sftpChannel.disconnect();' 

輸出

SFTP Channel created. 
Exception in thread "main" 2: No such file 
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2873) 
at com.jcraft.jsch.ChannelSftp._realpath(ChannelSftp.java:2367) 
at com.jcraft.jsch.ChannelSftp.cd(ChannelSftp.java:342) 
at fyp.Fyp.main(Fyp.java:53) 
+0

您的路徑不是絕對的。 'C:\'不在那裏。你怎麼錯過了:)? – Raghuveer

+0

你的意思是像這樣的「C:/ Program Files(x86)/ Syslogd/Logs」,我只是試過還沒有工作 –

回答

0

所以,我想這是路徑 「/ cygdrive/C /程序文件(x86)/ syslogd的/日誌」 和它的作品,但不知道如何?

+0

你還沒有告訴我們關於你的SSH服務器的任何信息,所以我們不能回答這個問題。雖然這可能會給你一些想法:https://winscp.net/eng/docs/faq_remote_drive –

+0

我在我的windows上安裝了openSSH。並創建了另一個用戶進行連接。 –

+0

有很多OpenSSH for Windows的端口。你使用了哪一個? –