I use the FileZilla client to upload files, and I found that on the FTP server side, it is impossible to distinguish between a completed upload and an interrupted upload.
Because I need to associate it with my business logic when uploading via FTP, I rewrote the Write and Close methods.
I have tried for a long time and cannot distinguish between a normal upload completion and an interrupted upload, so does this library have other ways to detect an interrupted file upload?
type monitoredFile struct {
afero.File
fs *callbackFs
filename string
transferred int64
nextReport int64
done bool
writeErr error
onProgress func(transferred int64) error
onCompleted func(total int64, err error) error
}
func (f *monitoredFile) Write(p []byte) (n int, err error) {
n, err = f.File.Write(p)
if err != nil {
f.writeErr = err
return
}
f.transferred += int64(n)
if f.transferred >= f.nextReport && f.onProgress != nil {
if cbErr := f.onProgress(f.transferred); cbErr != nil {
f.fs.logger.Printf("Warning: progress callback error: %v", cbErr)
}
f.nextReport = f.transferred + progressReportInterval
}
return
}
func (f *monitoredFile) Close() error {
if f.done {
return f.File.Close()
}
f.done = true
if f.transferred > 0 && f.transferred < f.nextReport && f.onProgress != nil {
if cbErr := f.onProgress(f.transferred); cbErr != nil {
f.fs.logger.Printf("Warning: progress callback error: %v", cbErr)
return cbErr
}
}
err := f.File.Close()
finalErr := f.writeErr
if finalErr == nil {
finalErr = err
}
if f.onCompleted != nil {
if cbErr := f.onCompleted(f.transferred, err); cbErr != nil {
f.fs.logger.Printf("Warning: completion callback error: %v", cbErr)
return cbErr
}
}
return finalErr
}
I use the FileZilla client to upload files, and I found that on the FTP server side, it is impossible to distinguish between a completed upload and an interrupted upload.
Because I need to associate it with my business logic when uploading via FTP, I rewrote the Write and Close methods.
I have tried for a long time and cannot distinguish between a normal upload completion and an interrupted upload, so does this library have other ways to detect an interrupted file upload?