プロジェクト

全般

プロフィール

バグ #322

未完了

SSH-3: ファイル操作機能実装 (4h)

Redmine Admin さんが約18時間前に追加.

ステータス:
新規
優先度:
高め
担当者:
-
開始日:
2025-06-07
期日:
進捗率:

0%

予定工数:

説明

SSH経由でのファイル読み取り・書き込み機能を実装する。

実装内容

ファイル読み取り

async readFile(userId: string, host: string, path: string) {
  const ssh = await this.getConnection(userId, host);
  
  try {
    const result = await ssh.execCommand(`cat "${path}"`);
    
    if (result.code !== 0) {
      throw new Error(`Failed to read file: ${result.stderr}`);
    }

    return {
      content: [{
        type: "text",
        text: result.stdout
      }]
    };
  } catch (error) {
    throw new Error(`File read failed: ${error.message}`);
  }
}

ファイル書き込み

async writeFile(userId: string, host: string, path: string, content: string, mode: string = "0644") {
  const ssh = await this.getConnection(userId, host);
  
  try {
    // 一時ファイルに書き込み
    const tempPath = `/tmp/mcp_${Date.now()}_${Math.random().toString(36).substring(7)}`;
    await ssh.execCommand(`cat > "${tempPath}"`, {
      stdin: content
    });

    // 本来の場所に移動
    await ssh.execCommand(`mv "${tempPath}" "${path}" && chmod ${mode} "${path}"`);

    return {
      content: [{
        type: "text",
        text: `File written successfully: ${path}`
      }]
    };
  } catch (error) {
    throw new Error(`File write failed: ${error.message}`);
  }
}

成果物

  • ファイル読み取り機能
  • ファイル書き込み機能
  • 権限設定機能

作業時間: 4時間

依存: SSH-2完了

表示するデータがありません

他の形式にエクスポート: Atom PDF