-
Notifications
You must be signed in to change notification settings - Fork 363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Walk example #293
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Yeah, I'm in the same boat. I looked at the tests for the Walker and then had a second look at the doco. func main() {
host := "ftp.something.host:21"
folder := "/some_folder"
user := "gonzo"
passwd := "secret"
c, err := ftp.Dial(host, ftp.DialWithTimeout(5*time.Second))
if err != nil {
log.Fatal(err)
}
err = c.Login(user, passwd)
if err != nil {
log.Fatal(err)
}
w := c.Walk(folder)
ok := w.Next() // Get next (first) entry in the tree
for ok == true {
e := w.Stat() // Get the current entry
fmt.Println(e.Type, e.Name, w.Path())
ok = w.Next() // Get next
}
if err := c.Quit(); err != nil {
log.Fatal(err)
}
} |
It's pretty similar to other libraries :) package main
import (
"fmt"
"io"
"log"
"time"
"github.com/jlaffaye/ftp"
)
func main() {
conn, err := ftp.Dial("your.host:21", ftp.DialWithTimeout(5*time.Second))
if err != nil {
log.Fatal(err)
}
if err = conn.Login("username", "password"); err != nil {
log.Fatal(err)
}
walker := conn.Walk("/your/path")
for walker.Next() {
// access current full path
fmt.Println(walker.Path())
// access entry (file or folder)
fmt.Println(walker.Stat().Name)
}
if walker.Err() != nil && walker.Err() != io.EOF {
log.Fatal(err)
}
if err = conn.Quit(); err != nil {
log.Fatal(err)
}
} |
Would someone be kind enough to share an example of how to use walk? Honestly i'm unable to work it out myself from the documentation (i'm still leaning go)
Thanks
The text was updated successfully, but these errors were encountered: