PhpStormでSFTPの接続に失敗する。

# PhpStormだとEC2へのSFTP接続に失敗する場合の対処法
## 接続に失敗していた時の状況
MacからsftpコマンドでEC2へSFTP接続はできました、
しかし、PhpStormの下記の画面でTest Connectionを行った時には接続に失敗するという状況でした。
![スクリーンショット 2021-06-27 19.26.39.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/72832/efda8d95-5e6c-31fa-e3c8-fc15f0347cf8.png)

## 解決方法
Tools > Start SSH Sesstion... からSFTP設定の内容（今回だとec2）が選べれるので、そこで一度SSH接続を行うと、Test Connectionで接続に成功するようになりました。
![スクリーンショット 2021-06-27 17.50.26.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/72832/273308ae-fde8-2456-d87b-feb1c37c8ef6.png)


## 備考
### 接続失敗時のidea.log
```
2021-06-27 19:26:27,651 [11155868]   WARN - t.connections.RemoteConnection - Retrying connecting to sftp://3.112.222.139:22/ in @7a82b01e: 1 iterations
org.apache.commons.vfs2.FileSystemException: Could not determine the type of file "sftp://3.112.222.139/".
        at org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:1437)
        at org.apache.commons.vfs2.provider.AbstractFileObject.isFile(AbstractFileObject.java:1605)
        at org.apache.commons.vfs2.provider.sftp.SftpFileObject.doListChildrenResolved(SftpFileObject.java:462)
        at org.apache.commons.vfs2.provider.AbstractFileObject.getChildren(AbstractFileObject.java:1091)
        at org.apache.commons.vfs2.provider.AbstractFileObject.getChild(AbstractFileObject.java:1044)
        at com.jetbrains.plugins.webDeployment.connections.RemoteConnectionPool.lambda$createConnection$0(RemoteConnectionPool.java:260)
        at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:311)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.commons.vfs2.FileSystemException: Could not connect to SFTP server at "sftp://3.112.222.139/".
        at com.jetbrains.plugins.webDeployment.connections.PatchedSftpFileSystem.getChannel(PatchedSftpFileSystem.java:108)
        at org.apache.commons.vfs2.provider.sftp.SftpFileObject.statSelf(SftpFileObject.java:177)
        at org.apache.commons.vfs2.provider.sftp.SftpFileObject.doGetType(SftpFileObject.java:112)
        at org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:1428)
        ... 11 more
Caused by: com.intellij.ssh.SshTransportException: reject HostKey: 3.112.222.139
        at com.intellij.ssh.impl.SshConnection.b(SshConnection.kt:134)
        at com.intellij.ssh.impl.SshConnection.openChannel(SshConnection.kt:68)
        at com.intellij.ssh.SshConnectionService.sftp(SshConnectionService.kt:165)
        at com.jetbrains.plugins.webDeployment.connections.PatchedSftpFileSystem.getChannel(PatchedSftpFileSystem.java:58)
        ... 14 more
Caused by: com.jcraft.jsch.JSchException: reject HostKey: 3.112.222.139
        at com.jcraft.jsch.Session.checkHost(Session.java:789)
        at com.jcraft.jsch.Session.connect(Session.java:345)
        at com.jcraft.jsch.Session.connect(Session.java:183)
        at com.intellij.ssh.impl.SshConnection.a(SshConnection.kt:156)
        at com.intellij.ssh.impl.SshConnection.b(SshConnection.kt:124)
        ... 17 more
2021-06-27 19:26:27,652 [11155869]   WARN - loyment.ui.WebServerConfigForm - Could not determine the type of file "sftp://3.112.222.139/".
org.apache.commons.vfs2.FileSystemException: Could not determine the type of file "sftp://3.112.222.139/".
        at org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:1437)
        at org.apache.commons.vfs2.provider.AbstractFileObject.isFile(AbstractFileObject.java:1605)
        at org.apache.commons.vfs2.provider.sftp.SftpFileObject.doListChildrenResolved(SftpFileObject.java:462)
        at org.apache.commons.vfs2.provider.AbstractFileObject.getChildren(AbstractFileObject.java:1091)
        at org.apache.commons.vfs2.provider.AbstractFileObject.getChild(AbstractFileObject.java:1044)
        at com.jetbrains.plugins.webDeployment.connections.RemoteConnectionPool.lambda$createConnection$0(RemoteConnectionPool.java:260)
        at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:311)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.commons.vfs2.FileSystemException: Could not connect to SFTP server at "sftp://3.112.222.139/".
        at com.jetbrains.plugins.webDeployment.connections.PatchedSftpFileSystem.getChannel(PatchedSftpFileSystem.java:108)
        at org.apache.commons.vfs2.provider.sftp.SftpFileObject.statSelf(SftpFileObject.java:177)
        at org.apache.commons.vfs2.provider.sftp.SftpFileObject.doGetType(SftpFileObject.java:112)
        at org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:1428)
        ... 11 more
Caused by: com.intellij.ssh.SshTransportException: reject HostKey: 3.112.222.139
        at com.intellij.ssh.impl.SshConnection.b(SshConnection.kt:134)
        at com.intellij.ssh.impl.SshConnection.openChannel(SshConnection.kt:68)
        at com.intellij.ssh.SshConnectionService.sftp(SshConnectionService.kt:165)
        at com.jetbrains.plugins.webDeployment.connections.PatchedSftpFileSystem.getChannel(PatchedSftpFileSystem.java:58)
        ... 14 more
Caused by: com.jcraft.jsch.JSchException: reject HostKey: 3.112.222.139
        at com.jcraft.jsch.Session.checkHost(Session.java:789)
        at com.jcraft.jsch.Session.connect(Session.java:345)
        at com.jcraft.jsch.Session.connect(Session.java:183)
        at com.intellij.ssh.impl.SshConnection.a(SshConnection.kt:156)
        at com.intellij.ssh.impl.SshConnection.b(SshConnection.kt:124)
        ... 17 more
2021-06-27 19:26:45,539 [11173756]   INFO - mponents.impl.stores.StoreUtil - saveProjectsAndApp took 152 ms
2021-06-27 19:26:45,604 [11173821]   WARN - t.connections.RemoteConnection - Forced closing file system of sftp://3.112.222.139:22/ in @7a82b01e
2021-06-27 19:27:00,530 [11188747]   INFO - mponents.impl.stores.StoreUtil - saveProjectsAndApp took 71 ms
```

#### idea.logの場所
Help > Show Log in Finder からidea.logのフォルダを開けます。
![スクリーンショット 2021-06-27 17.48.27.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/72832/b0757d15-82ae-ed0f-7047-68f19f7d4296.png)