# Connecting To SFTP With Go

My application needs to retrieve data files from remote SFTP server at regular interval. Sometime the files are not available at agreed time. So I need to monitor file availability and notify the person in charge. I wrote a Go script to check those files. Execution of this script and sending notifications is handled by [Monit](https://mmonit.com/monit/#about). If you like me to write about Monit, let me know in the comment.

%[https://gist.github.com/hongster/396af72c8a699d7e1abaa98b468a4bbd]

# Host Key Verification

```HostKeyCallback: ssh.InsecureIgnoreHostKey()```
[HostKeyCallback](https://pkg.go.dev/golang.org/x/crypto/ssh#HostKeyCallback) is a required attribute. The callback function should return nil if host key is accepted, or error to reject it. This [article](https://sftptogo.com/blog/go-sftp/) provides a method for verifying host key using "known_hosts" file.

[InsecureIgnoreHostKey](https://pkg.go.dev/golang.org/x/crypto/ssh#InsecureIgnoreHostKey) is used for convenience sake. It trust all host keys without any sort of verification.

# Further Reading

- Operations you can perform on files - https://pkg.go.dev/github.com/pkg/sftp#Client
- Ready-to-use host key verification functions - https://pkg.go.dev/golang.org/x/crypto/ssh#HostKeyCallback


