pkg / sftp

SFTP support for the go.crypto/ssh package
BSD 2-Clause "Simplified" License
1.52k stars 380 forks source link

The file sizes are all 4096 #488

Closed zhuxiujia closed 2 years ago

zhuxiujia commented 2 years ago
let walker = sftp.Client{}.Walk(basedir);
walker.Stat().Size()  //will be 4096,   But they're actually different sizes
puellanivis commented 2 years ago

We need more example code. It should be expected:

// assume an existing valid `client *sftp.Client`
walker := client.Walk(basedir)

for walker.Step() {
  fi := walker.Stat()
  fmt.Println(fi.Name(), ":", fi.Size())
}

if walker.Err() != nil {
  fmt.Println("unexpected error:", err)
}
zhuxiujia commented 2 years ago

fi.Size()

Yes, on the MAC OS, all of fi.size () is 4096, but it's really any number

puellanivis commented 2 years ago

We still need more details. Example code and output produced vs output expected is necessary for us to figure out where things might be going wrong.

drakkan commented 2 years ago

Hi,

I just did a quick test, using this code:

        walker := sftpClient.Walk("/Users/nicola/Downloads")
    for walker.Step() {
        err := walker.Err()
        if err != nil {
            fmt.Printf("walker error: %v\n", err)
            return
        }
        fmt.Printf("walker path %#v, isDir? %v, size %v\n", walker.Path(), walker.Stat().IsDir(), walker.Stat().Size())
    }

I get the expected output. The sftp client connects to OpenSSH running on MacOS and I launched the test program from both Linux and Mac and it works for me i both cases. Here is a sample output

walker path "/Users/nicola/Downloads/Azure Data Studio.app/Contents/Info.plist", isDir? false, size 3313
walker path "/Users/nicola/Downloads/Azure Data Studio.app/Contents/PkgInfo", isDir? false, size 8
walker path "/Users/nicola/Downloads/Win10_21H2_Italian_x32.iso", isDir? false, size 4122744832
walker path "/Users/nicola/Downloads/vcredist_x64.exe", isDir? false, size 10274136
walker path "/Users/nicola/Downloads/winget2", isDir? true, size 96
walker path "/Users/nicola/Downloads/winget2/manifests", isDir? true, size 96
walker path "/Users/nicola/Downloads/winget2/manifests/d", isDir? true, size 96
walker path "/Users/nicola/Downloads/winget2/manifests/d/drakkan", isDir? true, size 96
walker path "/Users/nicola/Downloads/winget2/manifests/d/drakkan/SFTPGo", isDir? true, size 96
walker path "/Users/nicola/Downloads/winget2/manifests/d/drakkan/SFTPGo/2.2.1", isDir? true, size 160
walker path "/Users/nicola/Downloads/winget2/manifests/d/drakkan/SFTPGo/2.2.1/drakkan.SFTPGo.locale.en-US.yaml", isDir? false, size 857
walker path "/Users/nicola/Downloads/winget2/manifests/d/drakkan/SFTPGo/2.2.1/drakkan.SFTPGo.installer.yaml", isDir? false, size 1141
walker path "/Users/nicola/Downloads/winget2/manifests/d/drakkan/SFTPGo/2.2.1/drakkan.SFTPGo.yaml", isDir? false, size 260
walker path "/Users/nicola/Downloads/Microsoft.WindowsPackageManagerManifestCreator_0.4.3.1_8wekyb3d8bbwe.msixbundle", isDir? false, size 78212427

Please reopen providing more info if you still have this issue, thanks