2013-02-18 16 views
7

Apache Common vfsを使用して新規です。 成功しました。サーバに接続しました。 私はすでにドキュメントを読んでいますが、 ディレクトリ/ファイルを一覧表示する方法はありますか?Apacheを使用してファイルディレクトリ/ファイルを一覧表示する方法

.... 
Session session = null; 
     FileSystemManager fsManager = null; 
     FileSystem fs = null; 
     try { 
      String host = "host_here"; 
      int port = 22; 

      String userStr = "user_here"; 
      char [] username = userStr.toCharArray(); 

      String passStr = "password_here"; 
      char [] password = passStr.toCharArray(); 

      session = SftpClientFactory.createConnection(host, port, username, password, null); 
      //session.connect(); 

      System.out.println("Connected to the server"); 

      FileSystemOptions opts = new FileSystemOptions(); 
      fsManager = VFS.getManager(); 
      FileObject file = fsManager.resolveFile("ftp://"+userStr+":"+passStr+"@"+host+"/home/", opts);  

      // .... whats next i do here? ..... 

     } catch (Exception e) { 
      session.disconnect(); 
      e.printStackTrace(); 
     } 
... 

ファイルの:)

答えて

6

一覧はFileObject#getChildren()メソッドを使用して表示することができます前に、 はありがとう、私を助けてください。

FileSystemOptions opts = new FileSystemOptions(); 
fsManager = VFS.getManager(); 

// List all the files in that directory.Try to give the directory path 
FileObject localFileObject=fsManager.resolveFile("ftp://"+userStr+":"+passStr+"@"+host+"/home"); 
FileObject[] children = localFileObject.getChildren(); 
for (int i = 0; i < children.length; i++){ 
    System.out.println(children[ i ].getName().getBaseName()); 
} 
// End of List Files. 

FileObject file = fsManager.resolveFile("ftp://"+userStr+":"+passStr+"@"+host+"/home/", opts); 

私の提案は、SFTP操作のために最善であるJSCHフレームワークを使用することであろう。このApache Common VFSは本質的にこのフレームワークを使用しました。複合体はJSCHで大幅に削減されます。

+0

JSCHを使用しています:D しかし、私は、ディレクトリ(ファイルではない)を保存先ディレクトリに保存する方法は不思議ですか? – fanjavaid

+0

新しいディレクトリを作成するか、すでにいくつかのファイルが入っているディレクトリを保存することを意味しますか? – SRy

+0

はい、そうです。それが可能だ? – fanjavaid

関連する問題