switch fileTransfer.Type {
case FileDownload:
+ s.Stats.DownloadCounter += 1
+
fullFilePath, err := readPath(s.Config.FileRoot, fileTransfer.FilePath, fileTransfer.FileName)
if err != nil {
return err
}
}
case FileUpload:
+ s.Stats.UploadCounter += 1
+
destinationFile := s.Config.FileRoot + ReadFilePath(fileTransfer.FilePath) + "/" + string(fileTransfer.FileName)
var file *os.File
i := 0
err = filepath.Walk(fullFilePath+"/", func(path string, info os.FileInfo, err error) error {
+ s.Stats.DownloadCounter += 1
+
if err != nil {
return err
}
}
fileSize := make([]byte, 4)
- readBuffer := make([]byte, 1024)
for i := 0; i < fileTransfer.ItemCount(); i++ {
- // TODO: fix potential short read with io.ReadFull
- _, err := conn.Read(readBuffer)
- if err != nil {
+ s.Stats.UploadCounter += 1
+
+ var fu folderUpload
+ if _, err := io.ReadFull(conn, fu.DataSize[:]); err != nil {
+ return err
+ }
+
+ if _, err := io.ReadFull(conn, fu.IsFolder[:]); err != nil {
+ return err
+ }
+ if _, err := io.ReadFull(conn, fu.PathItemCount[:]); err != nil {
+ return err
+ }
+ fu.FileNamePath = make([]byte, binary.BigEndian.Uint16(fu.DataSize[:])-4)
+
+ if _, err := io.ReadFull(conn, fu.FileNamePath); err != nil {
return err
}
- fu := readFolderUpload(readBuffer)
s.Logger.Infow(
"Folder upload continued",
nextAction = dlFldrActionResumeFile
}
- fmt.Printf("Next Action: %v\n", nextAction)
-
if _, err := conn.Write([]byte{0, uint8(nextAction)}); err != nil {
return err
}
}
case dlFldrActionSendFile:
- if _, err := conn.Read(fileSize); err != nil {
+ if _, err := io.ReadFull(conn, fileSize); err != nil {
return err
}