logger.Fatal(fmt.Errorf("invalid arguments passed to --sftp=%s",arg),"unable to start SFTP server")
}
switchtokens[0]{
case"address":
host,portStr,err:=net.SplitHostPort(tokens[1])
iferr!=nil{
logger.Fatal(fmt.Errorf("invalid arguments passed to --sftp=%s (%v)",arg,err),"unable to start SFTP server")
}
port,err=strconv.Atoi(portStr)
iferr!=nil{
logger.Fatal(fmt.Errorf("invalid arguments passed to --sftp=%s (%v)",arg,err),"unable to start SFTP server")
}
ifport<1||port>65535{
logger.Fatal(fmt.Errorf("invalid arguments passed to --sftp=%s, (port number must be between 1 to 65535)",arg),"unable to start SFTP server")
}
publicIP=host
case"ssh-private-key":
sshPrivateKey=tokens[1]
}
}
ifport==0{
port=8022// Default SFTP port, since no port was given.
}
ifsshPrivateKey==""{
logger.Fatal(fmt.Errorf("invalid arguments passed, private key file is mandatory for --sftp='ssh-private-key=path/to/id_ecdsa'"),"unable to start SFTP server")
}
privateBytes,err:=os.ReadFile(sshPrivateKey)
iferr!=nil{
logger.Fatal(fmt.Errorf("invalid arguments passed, private key file is not accessible: %v",err),"unable to start SFTP server")
}
private,err:=ssh.ParsePrivateKey(privateBytes)
iferr!=nil{
logger.Fatal(fmt.Errorf("invalid arguments passed, private key file is not parseable: %v",err),"unable to start SFTP server")
}
// An SSH server is represented by a ServerConfig, which holds
// certificate details and handles authentication of ServerConns.