Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "net"
- "os"
- "time"
- )
- func main() {
- var buf [0x100000]byte
- var sent_so_far int
- if len(os.Args) < 2 {
- println("Specify IP or hostname of the remote post")
- return
- }
- ip := os.Args[1] + ":11111"
- println("connecting to", ip, "...")
- con, e := net.DialTimeout("tcp4", ip, 10*time.Second)
- if e != nil {
- println(e.Error())
- return
- }
- println("ok. now sending", len(buf), "bytes...")
- var to_cnt int
- for sent_so_far < len(buf) {
- bts2s := len(buf) - sent_so_far
- if bts2s > 4096 {
- bts2s = 4096
- }
- con.SetWriteDeadline(time.Now().Add(1 * time.Millisecond))
- n, e := con.Write(buf[sent_so_far : sent_so_far+bts2s])
- if e != nil {
- if nerr, ok := e.(net.Error); ok && nerr.Timeout() {
- to_cnt++
- e = nil
- if n != 0 {
- println("n:", n)
- }
- } else {
- println(e.Error())
- return
- }
- }
- sent_so_far += n
- }
- println("closing socket...", to_cnt)
- con.Close()
- println(sent_so_far, "bytes sent. please check the file size at the other end")
- time.Sleep(1e9)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement