Skip to content

Instantly share code, notes, and snippets.

@Heavyblade
Created May 23, 2019 21:31
Show Gist options
  • Select an option

  • Save Heavyblade/2c9fc56ede5a8d371d4e11b0b60d4fd1 to your computer and use it in GitHub Desktop.

Select an option

Save Heavyblade/2c9fc56ede5a8d371d4e11b0b60d4fd1 to your computer and use it in GitHub Desktop.
copy.go
func main() {
/*user := C.CString("foo")
pass := C.CString("pass")
remote := C.CString("127.0.0.1")
port := C.CString("2222")
//pattern := C.CString("/upload")
fromPath := C.CString("/upload/2019040900050927.pdf")
toPath := C.CString("/upload/public/locales/my_pdf.pdf")
//toPath := C.CString("/upload/views/copy_2019040900050927.pdf")
// fmt.Println(C.GoString(ListPath(remote, port, user, pass, pattern)))
// fmt.Println(C.GoString(Download(remote, port, user, pass, fromPath, toPath)))
// fmt.Println(C.GoString(Delete(remote, port, user, pass, fromPath)))
// fmt.Println(C.GoString(Copy(remote, port, user, pass, fromPath, toPath)))
fmt.Println(C.GoString(Move(remote, port, user, pass, fromPath, toPath)))
*/
srcFile, err := os.Open("/home/cristianvasquez/go/src/vsftp/IMG_20190329_100716038.jpg")
if err != nil {
fmt.Println(err)
return
}
defer srcFile.Close()
dstFile, err2 := os.Create("/home/cristianvasquez/go/src/vsftp/IMG_20190329_100716038_copy.jpg")
if err2 != nil {
fmt.Println(err2)
return
}
defer dstFile.Close()
const bufferSize = 1048576 // 1 Mb
fileStat, _ := srcFile.Stat()
size := fileStat.Size()
loopValue := int(size / bufferSize)
last := int64(size % bufferSize)
for i := 0; i < loopValue; i++ {
if _, err := io.CopyN(dstFile, srcFile, bufferSize); err != nil {
log.Fatal(err)
}
}
if last > 0 {
if _, err := io.CopyN(dstFile, srcFile, last); err != nil {
log.Fatal(err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment