# Google Cloud Platform 使用FTP上傳程式(mac版)
###### tags: GCP
這次帶著GDG Taichung進行cloud study jam
也是我第一次玩Google Cloud Platform
不然就趁著這次學習順便把我的blog架在Google Cloud Platform
照著study jam的[Creating a Virtual Machine](https://hackmd.io/n4T3DLpQR0a0LSTofxmQZw)步驟架了一個站,裝了NGINX web server(沒有用過)
然後就遇到兩大困難
1. 上傳程式
2. 接firestore資料
所以這篇就紀錄了一下怎麼使用FTP連上GCP instance上傳程式
兩大步驟
1. 產生金鑰
2. 使用金鑰檔案連線FTP
看起來很簡單,但兩個步驟要完成還真不是普通的麻煩
這篇記錄mac的執行步驟,在windows的執行步驟可[參考](https://sammy197.tw/4061/%E5%9C%A8gcp%EF%BC%88google-cloud-platform%EF%BC%89%E4%B8%8A%E9%80%8F%E9%81%8Eftp%E4%B8%8A%E5%82%B3%E6%AA%94%E6%A1%88/)
## 產生金鑰
### 安裝CLOUD SDK
至[https://cloud.google.com/sdk/](https://cloud.google.com/sdk/)下載CLOUD SDK
![](https://i.imgur.com/avo1yq7.png)
下載後解壓縮,開啟終端機執行
```
./install.sh
```
歡迎頁面,輸入Y
```
Welcome to the Google Cloud SDK!
To help improve the quality of this product, we collect anonymized usage data
and anonymized stacktraces when crashes are encountered; additional information
is available at <https://cloud.google.com/sdk/usage-statistics>. You may choose
to opt out of this collection now (by choosing 'N' at the below prompt), or at
any time in the future by running the following command:
gcloud config set disable_usage_reporting true
Do you want to help improve the Google Cloud SDK (Y/n)?
```
繼續輸入Y
```
To install or remove components at your current SDK version [218.0.0], run:
$ gcloud components install COMPONENT_ID
$ gcloud components remove COMPONENT_ID
To update your SDK installation to the latest version [240.0.0], run:
$ gcloud components update
Modify profile to update your $PATH and enable shell command
completion?
Do you want to continue (Y/n)?
```
問你要不要更新你的環境,並且複寫.bash_profile
直接enter
```
The Google Cloud SDK installer will now prompt you to update an rc
file to bring the Google Cloud CLIs into your environment.
Enter a path to an rc file to update, or leave blank to use
[/Users/inalai/.bash_profile]:
```
安裝成功
```
For more information on how to get started, please visit:
https://cloud.google.com/sdk/docs/quickstarts
InadeMacBook-Air:google-cloud-sdk inalai$
```
### 產生金鑰
安裝Cloud SDK成功後,關掉終端機再開一次
這次我們要直接連上GCP的instance並且在本地端產生金鑰
重新開啟終端機後,輸入指令
```
gcloud init
```
第一次執行會跳出google登入視窗,請允許
![](https://i.imgur.com/m0LfmCT.png)
回到終端機的部分,會顯示出你所有的project id
選擇要連線的project
![](https://i.imgur.com/3ZbB5Ta.png)
project id的可讀性不高,可以參考project name
![](https://i.imgur.com/IhWrKwK.png)
選擇當初建立instance時的區域位置
![](https://i.imgur.com/qwsTmMR.png)
![](https://i.imgur.com/dVPvwVB.png)
連線囉!!記得把[instance_name]換成你的
```
gcloud compute ssh [instance_name]
```
輸入兩次enter產生金鑰
![](https://i.imgur.com/QYy7mzs.png)
這裡會有key的產生位置
![](https://i.imgur.com/dsYXDZ9.png)
## 使用金鑰檔案連線FTP
以File Zilla為例,使用SFTP連線,輸入剛剛產生的金鑰位置
![](https://i.imgur.com/NdUsWF7.png)
使用者名稱請看這邊
![](https://i.imgur.com/S7kunTT.png)
連線成功後預設位置會在 **/home/使用者名稱**
透過SFTP上傳檔案只能放在這個位置下(**/home/使用者名稱**)
放其他位置會說沒有權限,先放這邊之後再使用mv指令移動檔案
![](https://i.imgur.com/lVyk6cU.png)
移動前記得先切換帳號到root
```
sudo su -
```
使用移動檔案
```
mv index.html /var/www/
```
參考資料
[在GCP(Google Cloud Platform)上透過FTP上傳檔案](https://sammy197.tw/4061/%E5%9C%A8gcp%EF%BC%88google-cloud-platform%EF%BC%89%E4%B8%8A%E9%80%8F%E9%81%8Eftp%E4%B8%8A%E5%82%B3%E6%AA%94%E6%A1%88/)