# 【extension】sftp

### 產生Config

vscode 按下 Ctrl + Shift + P

輸入 SFTP:Config

---

[![image-1638770235855.png](https://bookstack.treemanou.com/uploads/images/gallery/2021-12/scaled-1680-/tNIi6QkOATYpcsHp-image-1638770235855.png)](https://bookstack.treemanou.com/uploads/images/gallery/2021-12/tNIi6QkOATYpcsHp-image-1638770235855.png)

### Config 相關

---

單一來源

```JSON
[
  {
    "name": "demo_10.1.1.1",
    "context": "D:\\php_workspace\\demo",
    "host": "10.1.1.1",
    "username": "user1",
    "password": "12345678",
    "remotePath": "/root"
	}
]
```

多個來源

```JSON
[
  {
    "name": "demo_10.1.1.1",
    "context": "D:\\php_workspace\\demo\web1",
    "host": "10.1.1.1",
    "username": "user1",
    "password": "12345678",
    "remotePath": "/root"
	},
     {
    "name": "demo_10.1.1.2",
    "context": "D:\\php_workspace\\demo\web2",
    "host": "10.1.1.2",
    "username": "user1",
    "password": "12345678",
    "remotePath": "/root"
	},
]
```

使用跳板機(帳號密碼)

```JSON
[
{
    "name": "jump_demo",
    "remotePath": "/root",
    "context": "D:\\php_workspace\\jump_demo",
    
    "host": "10.1.1.1", 	// 跳板機ip
    "username": "user1",	// 跳板機 帳號
    "password": "12345678", // 跳板機 密碼
    
    "hop": {
        "host": "192.168.1.1", // 目的地ip
        "port": 22,
        "username": "target_user",	// 目的地 帳號
        "password": "66778899"		// 目的地 密碼
    },
    // 排除檔案
    "ignore": [
        ".vscode",
        ".git",
        ".DS_Store",
        "**/logs/**",
        "**/sessions/**"
    ],
  	// 儲存後自動上傳
    "uploadOnSave": false
}
]
```

使用跳板機(憑證)

```JSON
[
{
    "name": "jump_demo",
    "remotePath": "/root",
    "context": "D:\\php_workspace\\jump_demo",
    
    "host": "10.1.1.1", // 跳板機ip
    "username": "user1",
    "password": "12345678",   
    
    "hop": {
        "host": "192.168.1.1", // 目的地ip
        "port": 22,
        "username": "target_user",
        "privateKeyPath": "/home/user1/.ssh/id_rsa" //使用憑證(跳板機位置)
    },
    // 排除檔案
    "ignore": [
        ".vscode",
        ".git",
        ".DS_Store",
        "**/logs/**",
        "**/sessions/**"
    ],
  	// 儲存後自動上傳
    "uploadOnSave": false
}
]
```

第一次設定完，可以按下【Ctrl + Shift + P 】(Mac: Cmd + Shift + P)

鍵入 &gt;SFTP:Sync Remote -&gt; Local

先將遠端資料同步至本機

[![image-1657186191829.png](https://bookstack.treemanou.com/uploads/images/gallery/2022-07/scaled-1680-/zOtmW2iuNdnjImut-image-1657186191829.png)](https://bookstack.treemanou.com/uploads/images/gallery/2022-07/zOtmW2iuNdnjImut-image-1657186191829.png)

---

### 瀏覽遠端檔案/選取Server檔案至本地編輯

選取左側icon

[![image-1657186997112.png](https://bookstack.treemanou.com/uploads/images/gallery/2022-07/scaled-1680-/TfAGHB74KNUTyp4L-image-1657186997112.png)](https://bookstack.treemanou.com/uploads/images/gallery/2022-07/TfAGHB74KNUTyp4L-image-1657186997112.png)

，展開目錄找到要編輯檔案，【Edit in Local】

[![image-1657186787174.png](https://bookstack.treemanou.com/uploads/images/gallery/2022-07/scaled-1680-/dYCIqlAbr2GaUdNP-image-1657186787174.png)](https://bookstack.treemanou.com/uploads/images/gallery/2022-07/dYCIqlAbr2GaUdNP-image-1657186787174.png)

[![image-1657186848499.png](https://bookstack.treemanou.com/uploads/images/gallery/2022-07/scaled-1680-/Cvf7ePo36wLHdG1l-image-1657186848499.png)](https://bookstack.treemanou.com/uploads/images/gallery/2022-07/Cvf7ePo36wLHdG1l-image-1657186848499.png)

---

### 檔案比較

在本地編輯的時候，可以按右鍵【Diff with Remote】與server 檔案比較

[![image-1657186402680.png](https://bookstack.treemanou.com/uploads/images/gallery/2022-07/scaled-1680-/gQD3mLHQYxZVPA3B-image-1657186402680.png)](https://bookstack.treemanou.com/uploads/images/gallery/2022-07/gQD3mLHQYxZVPA3B-image-1657186402680.png)

---

###  

###  

---

### 上傳，下載檔案

可以按右鍵，【Upload/ Download】上傳本地檔案至Server 或是 下載Server 檔案

[![image-1657186492797.png](https://bookstack.treemanou.com/uploads/images/gallery/2022-07/scaled-1680-/1YDtrGQUAJ1ZCsE6-image-1657186492797.png)](https://bookstack.treemanou.com/uploads/images/gallery/2022-07/1YDtrGQUAJ1ZCsE6-image-1657186492797.png)

---