Ejemplo n.º 1
0
func newPassiveSocket(logger *ftpLogger, passiveOpts *PassiveOpts, tlsConfig *tls.Config) (*ftpPassiveSocket, error) {
	socket := &ftpPassiveSocket{
		listener:      nil,
		listenerMutex: &sync.RWMutex{},
		conn:          nil,
		connMutex:     &sync.RWMutex{},
		closed:        false,
		closedMutex:   &sync.RWMutex{},
		connected:     goevent.NewEvent(),
		host:          "",
		port:          0,
		logger:        logger,
		passiveOpts:   passiveOpts,
		tlsConfig:     tlsConfig,
	}

	listener, err := socket.createListener()

	if err != nil {
		return nil, fmt.Errorf("newPassiveSocket socket could not be created: %s", err)
	}

	socket.listener = listener

	go socket.acceptConnection()

	return socket, nil
}
Ejemplo n.º 2
0
func newActiveSocket(host string, port int, logger *ftpLogger) (*ftpActiveSocket, error) {
	connectTo := buildTcpString(host, port)
	logger.Print("Opening active data connection to " + connectTo)
	raddr, err := net.ResolveTCPAddr("tcp", connectTo)
	if err != nil {
		logger.Print(err)
		return nil, err
	}
	tcpConn, err := net.DialTCP("tcp", nil, raddr)
	if err != nil {
		logger.Print(err)
		return nil, err
	}
	socket := new(ftpActiveSocket)
	socket.conn = tcpConn
	socket.host = host
	socket.port = port
	socket.logger = logger
	socket.connected = goevent.NewEvent()
	socket.connected.Set()
	return socket, nil
}