ftp
ftp copied to clipboard
When I try to get all the files in the directory, the list of files I get is empty
Describe the bug I use the Walk method to get the file traversal, but can not get the file in the directory, but there are files in the directory
To Reproduce
file, err := os.Open(indexTableName)
if err != nil {
log.Println(fmt.Sprintf("open file failed, %s;", err))
}
oldFileAbsPath := make(map[string]struct{})
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
oldFileAbsPath[line] = struct{}{}
}
_ = file.Close()
err = conn.Conn.ChangeDir(remoteFolderPath)
if err != nil {
oldFileAbsPath = nil
return nil, errors.New(fmt.Sprintf("path failed:%s,:%s", remoteFolderPath, err))
}
fileAbsPath := make(map[string]string)
pathsSplit := strings.Split(remoteFolderPath, "/")
walker := conn.Conn.Walk(remoteFolderPath)
var builder strings.Builder
for walker.Next() {
info := walker.Stat()
if info.Type.String() == "folder" {
continue
}
if info == nil {
continue
}
v := walker.Path()
vSplit := strings.Split(path.Dir(v), "/")
if len(vSplit)-1 > (len(pathsSplit)-1+folderLevel) && folderLevel > 0 && folderLevel != 0 {
continue
}
builder.WriteString(v)
builder.WriteRune('-')
builder.WriteString(strconv.FormatUint(info.Size, 10))
builder.WriteRune('-')
builder.WriteString(info.Time.Format("20060102150405"))
m5 := builder.String()
//m5 := v + "-" + strconv.FormatUint(info.Size, 10) + "-" + info.Time.Format("20060102150405")
if _, ok := oldFileAbsPath[m5]; !ok {
fileAbsPath[v] = m5
}
builder.Reset()
}
if err = walker.Err(); err != nil {
log.Println(fmt.Sprintf("path failed:%s,:%s", remoteFolderPath, err))
}
oldFileAbsPath = nil
FTP server
- Name and version: vsftpd 3.0.2
Additional context Is it related to the file system string?
Looking forward to reply! 🤣