本文整理匯總了Golang中github.com/pkg/sftp.Client.Open方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Open方法的具體用法?Golang Client.Open怎麽用?Golang Client.Open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pkg/sftp.Client
的用法示例。
在下文中一共展示了Client.Open方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FileOpen
func FileOpen(s *sftp.Client, name string) (*File, error) {
fd, err := s.Open(name)
if err != nil {
return &File{}, err
}
return &File{fd: fd}, nil
}
示例2: GetFile
func (conn *SshConfig) GetFile(rPath, lPath string, sftp *sftp.Client, env *Enviroment) error {
remoteFile, err := sftp.Open(rPath)
if err != nil {
return err
}
localFile, err := os.OpenFile(lPath, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0755)
if err != nil {
return err
}
defer localFile.Close()
if env.filter.on {
// filter lines in the file that match the filter key
fmt.Printf("downloading and applying filter to %s:%s\n", conn.Name, rPath)
scanner := bufio.NewScanner(remoteFile)
for scanner.Scan() {
if LineMatch(scanner.Bytes(), env.filter.key) {
if _, err = localFile.Write([]byte(scanner.Text() + "\n")); err != nil {
return err
}
}
}
srcStat, err := localFile.Stat()
if err != nil {
return err
}
if (srcStat.Size()) == 0 {
localFile.Write([]byte("No matches found."))
}
return nil
}
srcStat, err := remoteFile.Stat()
if err != nil {
return err
}
writer := io.Writer(localFile)
io.Copy(writer, remoteFile)
fmt.Printf("%s @filesize %dB <-- %s\n", lPath, srcStat.Size(), PathChomp(rPath))
localFile.Sync()
return nil
}