func TrzMain() int {
	var args TrzArgs
	arg.MustParse(&args)

	var err error
	args.Path, err = filepath.Abs(args.Path)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return -1
	}
	if err := checkPathWritable(args.Path); err != nil {
		fmt.Fprintln(os.Stderr, err)
		return -2
	}

	tmuxMode, realStdout, tmuxPaneWidth, err := checkTmux()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return -3
	}

	if args.Binary && tmuxMode != NoTmux {
		os.Stdout.WriteString("Binary upload in tmux is not supported, auto switch to base64 mode.\n")
		args.Binary = false
	}
	if args.Binary && IsWindows() {
		os.Stdout.WriteString("Binary upload on Windows is not supported, auto switch to base64 mode.\n")
		args.Binary = false
	}

	uniqueID := "0"
	if tmuxMode == TmuxNormalMode {
		columns := getTerminalColumns()
		if columns > 0 && columns < 40 {
			os.Stdout.WriteString("\n\n\x1b[2A\x1b[0J")
		} else {
			os.Stdout.WriteString("\n\x1b[1A\x1b[0J")
		}
		uniqueID = reverseString(strconv.FormatInt(time.Now().UnixMilli(), 10))
	}
	if IsWindows() {
		uniqueID = "1"
	}

	mode := "R"
	if args.Directory {
		mode = "D"
	}
	os.Stdout.WriteString(fmt.Sprintf("\x1b7\x07::TRZSZ:TRANSFER:%s:%s:%s\n", mode, kTrzszVersion, uniqueID))
	os.Stdout.Sync()

	state, err := term.MakeRaw(int(os.Stdin.Fd()))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return -4
	}
	defer func() { _ = term.Restore(int(os.Stdin.Fd()), state) }()

	transfer := NewTransfer(realStdout, state)
	defer func() {
		if err := recover(); err != nil {
			transfer.serverError(NewTrzszError(fmt.Sprintf("%v", err), "panic", true))
		}
	}()

	go wrapStdinInput(transfer)
	handleServerSignal(transfer)

	if err := recvFiles(transfer, &args, tmuxMode, tmuxPaneWidth); err != nil {
		transfer.serverError(err)
	}

	return 0
}
// TrzMain entry of recevie files from client
TrzMain entry of recevie files from client
// TrzMain entry of recevie files from client
func TrzMain() int {
	var args TrzArgs
	arg.MustParse(&args)
	var err error
	args.Path, err = filepath.Abs(args.Path)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return -1
	}
	if err := checkPathWritable(args.Path); err != nil {
		fmt.Fprintln(os.Stderr, err)
		return -2
	}
	tmuxMode, realStdout, tmuxPaneWidth, err := checkTmux()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return -3
	}
	if args.Binary && tmuxMode != NoTmux {
		os.Stdout.WriteString("Binary upload in tmux is not supported, auto switch to base64 mode.\n")
		args.Binary = false
	}
	if args.Binary && IsWindows() {
		os.Stdout.WriteString("Binary upload on Windows is not supported, auto switch to base64 mode.\n")
		args.Binary = false
	}
	uniqueID := "0"
	if tmuxMode == TmuxNormalMode {
		columns := getTerminalColumns()
		if columns > 0 && columns < 40 {
			os.Stdout.WriteString("\n\n\x1b[2A\x1b[0J")
		} else {
			os.Stdout.WriteString("\n\x1b[1A\x1b[0J")
		}
		uniqueID = reverseString(strconv.FormatInt(time.Now().UnixMilli(), 10))
	}
	if IsWindows() {
		uniqueID = "1"
	}
	mode := "R"
	if args.Directory {
		mode = "D"
	}
	os.Stdout.WriteString(fmt.Sprintf("\x1b7\x07::TRZSZ:TRANSFER:%s:%s:%s\n", mode, kTrzszVersion, uniqueID))
	os.Stdout.Sync()
	state, err := term.MakeRaw(int(os.Stdin.Fd()))
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return -4
	}
	defer func() { _ = term.Restore(int(os.Stdin.Fd()), state) }()
	transfer := NewTransfer(realStdout, state)
	defer func() {
		if err := recover(); err != nil {
			transfer.serverError(NewTrzszError(fmt.Sprintf("%v", err), "panic", true))
		}
	}()
	go wrapStdinInput(transfer)
	handleServerSignal(transfer)
	if err := recvFiles(transfer, &args, tmuxMode, tmuxPaneWidth); err != nil {
		transfer.serverError(err)
	}
	return 0
}
func TrzMain ( ) int { var args TrzArgs arg . MustParse ( & args ) var err error args . Path , err = filepath . Abs ( args . Path ) if err != nil { fmt . Fprintln ( os . Stderr , err ) return - 1 } if err := checkPathWritable ( args . Path ) ; err != nil { fmt . Fprintln ( os . Stderr , err ) return - 2 } tmuxMode , realStdout , tmuxPaneWidth , err := checkTmux ( ) if err != nil { fmt . Fprintln ( os . Stderr , err ) return - 3 } if args . Binary && tmuxMode != NoTmux { os . Stdout . WriteString ( " \n " ) args . Binary = false } if args . Binary && IsWindows ( ) { os . Stdout . WriteString ( " \n " ) args . Binary = false } uniqueID := " " if tmuxMode == TmuxNormalMode { columns := getTerminalColumns ( ) if columns > 0 && columns < 40 { os . Stdout . WriteString ( " \n \n \x1b \x1b " ) } else { os . Stdout . WriteString ( " \n \x1b \x1b " ) } uniqueID = reverseString ( strconv . FormatInt ( time . Now ( ) . UnixMilli ( ) , 10 ) ) } if IsWindows ( ) { uniqueID = " " } mode := " " if args . Directory { mode = " " } os . Stdout . WriteString ( fmt . Sprintf ( " \x1b \x07 \n " , mode , kTrzszVersion , uniqueID ) ) os . Stdout . Sync ( ) state , err := term . MakeRaw ( int ( os . Stdin . Fd ( ) ) ) if err != nil { fmt . Fprintln ( os . Stderr , err ) return - 4 } defer func ( ) { _ = term . Restore ( int ( os . Stdin . Fd ( ) ) , state ) } ( ) transfer := NewTransfer ( realStdout , state ) defer func ( ) { if err := recover ( ) ; err != nil { transfer . serverError ( NewTrzszError ( fmt . Sprintf ( " " , err ) , " " , true ) ) } } ( ) go wrapStdinInput ( transfer ) handleServerSignal ( transfer ) if err := recvFiles ( transfer , & args , tmuxMode , tmuxPaneWidth ) ; err != nil { transfer . serverError ( err ) } return 0 }
TrzMain entry of recevie files from client
TrzMain entry of recevie files from client