2016-04-13 6 views
0

FTP/SFTP接続を使用してリモートサーバーのディレクトリを検索するツリービューを作成しようとしています。行うには、次の例のようにホームディレクトリから始まるすべての使用可能なディレクトリでツリービューを充填開始です:ユーザーは、各フォルダをクリック起動したときWinSCPとC言語のリモートディレクトリからツリービューのノードを追加する方法

Home---->SubFolder 
    | 
    |---->Another Folder 
    | 
    |---->MyOtherFolder 

そして、それは、ツリービューからそのサブディレクトリを表示するために開始次の例(別のフォルダをクリック)として:

Home ---->SubFolder 
    | 
    |---->Another Folder -------> MyFolder1 
    |     | -------> MyFolder2 
    | 
    |---->MyOtherFolder 

private void FillTree() 
{ 
    SessionOptions SessionOptions = new SessionOptions(); 
    Session MySession = new Session(); 

    SessionOptions.HostName = InterfaceValues[0]; 
    SessionOptions.UserName = InterfaceValues[2]; 
    SessionOptions.Password = InterfaceValues[3]; 
    SessionOptions.PortNumber = Convert.ToInt32(InterfaceValues[1]); 

    if (string.Compare(InterfaceValues[9], "FTP", true) == 0) 
     SessionOptions.Protocol = WinSCP.Protocol.Ftp; 
    else if (string.Compare(InterfaceValues[9], "SFTP", true) == 0) 
    { 
     SessionOptions.Protocol = WinSCP.Protocol.Sftp; 
     SessionOptions.SshPrivateKeyPath = InterfaceValues[12]; 
     SessionOptions.SshHostKeyFingerprint = InterfaceValues[10]; 
    } 

    try 
    { 
     MySession.Open(SessionOptions); 

     foreach (RemoteFileInfo info in MySession.EnumerateRemoteFiles("/", "*", EnumerationOptions.AllDirectories)) 
     { 
      if (info.IsDirectory) 
      tvRemoteDirectory.Nodes.Add(info.Name); 
     } 

    MySession.Close(); 
} 
catch (Exception ex) 
{ 
    MySession.Close(); 
    MessageBox.Show("Not possible to connect to " + InterfaceValues[0] + "\nError Message: " + ex.Message); 
     this.Close(); 
} 

....これは私が持っているコードです....

を私はこれらのフォルダを取得しようとしているが、それは例外を投げ、またそれはファイルではなくフォルダを集めています私は取得しています例外は次のとおりです。

{WinSCP.SessionRemoteException: Error listing directory '/jpm_icl'. ---> WinSCP.SessionRemoteException: Permission denied. Error code: 3 Error message from server: Permission Denied!

私はこの時点で何ができるかを任意のアイデア?使用RadFileExplorer - Telerik ASP.NET FileExplorer

+1

エラーを無視するか、許可を得てください。 – SLaks

+0

私はこれを試しました: 'RemoteDirectoryInfo RemoteDirectory = MySession.ListDirectory("/"); foreach(RemoteDirectory.FilesのRemoteFileInfoファイルインフォメーション) { //tvRemoteDirectory.Nodes.Add(fileinfo.Name); } 「 」が取得されています。 ".."と "jpm_icl"しかし、私はアイデアを持っていません "jpm_icl"については、私はそのフォルダを見ることができません –

+0

あなたは例外をいつ取得しますか? 'EnumerateRemoteFiles'ループでは?あなたは 'jpm_icl'フォルダを見ることができません? –

答えて

-1

そして、この機能を使用すると、希望FileExplorer - Show all items in the TreeView

他のすべての主な特長は以下に示す要件を完了しますそれあなたがいずれかのために、この機能を得ることができますTelerikから

プラットフォーム。

  • Telerik.Web.UIで統合された単一の制御、 -

  • ASP.NET 2.0 AJAXコールバックメカニズムを使用してオンデマンド負荷に

  • Directoryの負荷ページでドラッグ&ドロップする準備ができて

  • ファイル操作のクライアントイベントとサーバイベント

  • RadEditorのFileBrowserContentProvider抽象化を使用して、下位のfiにフックしますこのようなファイルやフォルダ

  • コンテキストメニュー

  • ファイルを削除し、名前を変更する機能やフォルダ

  • 能力へのOS、データベース、MOSSのSharePoint、MCMS

  • ソートなどルシステム、新しいフォルダを作成する

  • フォルダに多数のアイテムが含まれている場合、グリッドのページングを有効にする機能私のように、すべてのディレクトリを取得するための

    ListDirectory機能:新しいツールバーのボタンを使用してグリッドとサムネイルビュー間をすばやく切り替えるには200以上)

  • 能力私が何をしたか

+0

申し訳ありませんが、これはウェブではなくウィンドウフォームです。 –

1

このでしたディレクトリを必要としません。 "と "。"私はそれを除外しなければならない。

RemoteDirectoryInfo RemoteDirectory; 

    if (RemoteDirectoryPath != "Home") 
      RemoteDirectory = MySession.ListDirectory(RemoteDirectoryPath); 
    else 
      RemoteDirectory = MySession.ListDirectory("/"); 
    if (tvRemoteDirectory.SelectedNode.Nodes.Count > 0) tvRemoteDirectory.SelectedNode.Nodes.Clear(); 

    foreach (RemoteFileInfo fileinfo in RemoteDirectory.Files) 
    {      
     if (fileinfo.IsDirectory) 
     { 
      if (fileinfo.Name != "." && 
       fileinfo.Name != "..") 
       {              
        TreeNode ChildNode = new TreeNode(); 
        ChildNode.Text = fileinfo.Name; 
        ChildNode.ImageIndex = 0;              
        tvRemoteDirectory.SelectedNode.Nodes.Add(ChildNode); 
        tvRemoteDirectory.ExpandAll(); 
       }   
     }      
    } 
関連する問題