@@ -28,7 +28,7 @@ type Conn struct {
2828 logger * Logger
2929 server * Server
3030 tlsConfig * tls.Config
31- sessionId string
31+ sessionID string
3232 namePrefix string
3333 reqUser string
3434 user string
@@ -48,7 +48,7 @@ func (conn *Conn) IsLogin() bool {
4848}
4949
5050// returns a random 20 char string that can be used as a unique session ID
51- func newSessionId () string {
51+ func newSessionID () string {
5252 hash := sha256 .New ()
5353 _ , err := io .CopyN (hash , rand .Reader , 50 )
5454 if err != nil {
@@ -100,39 +100,39 @@ func (conn *Conn) Close() {
100100 }
101101}
102102
103- func (Conn * Conn ) upgradeToTls () error {
104- Conn .logger .Print ("Upgrading connectiion to TLS" )
105- tlsConn := tls .Server (Conn .conn , Conn .tlsConfig )
103+ func (conn * Conn ) upgradeToTLS () error {
104+ conn .logger .Print ("Upgrading connectiion to TLS" )
105+ tlsConn := tls .Server (conn .conn , conn .tlsConfig )
106106 err := tlsConn .Handshake ()
107107 if err == nil {
108- Conn .conn = tlsConn
109- Conn .controlReader = bufio .NewReader (tlsConn )
110- Conn .controlWriter = bufio .NewWriter (tlsConn )
111- Conn .tls = true
108+ conn .conn = tlsConn
109+ conn .controlReader = bufio .NewReader (tlsConn )
110+ conn .controlWriter = bufio .NewWriter (tlsConn )
111+ conn .tls = true
112112 }
113113 return err
114114}
115115
116116// receiveLine accepts a single line FTP command and co-ordinates an
117117// appropriate response.
118- func (Conn * Conn ) receiveLine (line string ) {
119- command , param := Conn .parseLine (line )
120- Conn .logger .PrintCommand (command , param )
118+ func (conn * Conn ) receiveLine (line string ) {
119+ command , param := conn .parseLine (line )
120+ conn .logger .PrintCommand (command , param )
121121 cmdObj := commands [strings .ToUpper (command )]
122122 if cmdObj == nil {
123- Conn .writeMessage (500 , "Command not found" )
123+ conn .writeMessage (500 , "Command not found" )
124124 return
125125 }
126126 if cmdObj .RequireParam () && param == "" {
127- Conn .writeMessage (553 , "action aborted, required param missing" )
128- } else if cmdObj .RequireAuth () && Conn .user == "" {
129- Conn .writeMessage (530 , "not logged in" )
127+ conn .writeMessage (553 , "action aborted, required param missing" )
128+ } else if cmdObj .RequireAuth () && conn .user == "" {
129+ conn .writeMessage (530 , "not logged in" )
130130 } else {
131- cmdObj .Execute (Conn , param )
131+ cmdObj .Execute (conn , param )
132132 }
133133}
134134
135- func (Conn * Conn ) parseLine (line string ) (string , string ) {
135+ func (conn * Conn ) parseLine (line string ) (string , string ) {
136136 params := strings .SplitN (strings .Trim (line , "\r \n " ), " " , 2 )
137137 if len (params ) == 1 {
138138 return params [0 ], ""
@@ -141,11 +141,11 @@ func (Conn *Conn) parseLine(line string) (string, string) {
141141}
142142
143143// writeMessage will send a standard FTP response back to the client.
144- func (Conn * Conn ) writeMessage (code int , message string ) (wrote int , err error ) {
145- Conn .logger .PrintResponse (code , message )
144+ func (conn * Conn ) writeMessage (code int , message string ) (wrote int , err error ) {
145+ conn .logger .PrintResponse (code , message )
146146 line := fmt .Sprintf ("%d %s\r \n " , code , message )
147- wrote , err = Conn .controlWriter .WriteString (line )
148- Conn .controlWriter .Flush ()
147+ wrote , err = conn .controlWriter .WriteString (line )
148+ conn .controlWriter .Flush ()
149149 return
150150}
151151
@@ -166,43 +166,43 @@ func (Conn *Conn) writeMessage(code int, message string) (wrote int, err error)
166166// The driver implementation is responsible for deciding how to treat this path.
167167// Obviously they MUST NOT just read the path off disk. The probably want to
168168// prefix the path with something to scope the users access to a sandbox.
169- func (Conn * Conn ) buildPath (filename string ) (fullPath string ) {
169+ func (conn * Conn ) buildPath (filename string ) (fullPath string ) {
170170 if len (filename ) > 0 && filename [0 :1 ] == "/" {
171171 fullPath = filepath .Clean (filename )
172172 } else if len (filename ) > 0 && filename != "-a" {
173- fullPath = filepath .Clean (Conn .namePrefix + "/" + filename )
173+ fullPath = filepath .Clean (conn .namePrefix + "/" + filename )
174174 } else {
175- fullPath = filepath .Clean (Conn .namePrefix )
175+ fullPath = filepath .Clean (conn .namePrefix )
176176 }
177177 fullPath = strings .Replace (fullPath , "//" , "/" , - 1 )
178178 return
179179}
180180
181181// sendOutofbandData will send a string to the client via the currently open
182182// data socket. Assumes the socket is open and ready to be used.
183- func (Conn * Conn ) sendOutofbandData (data []byte ) {
183+ func (conn * Conn ) sendOutofbandData (data []byte ) {
184184 bytes := len (data )
185- if Conn .dataConn != nil {
186- Conn .dataConn .Write (data )
187- Conn .dataConn .Close ()
188- Conn .dataConn = nil
185+ if conn .dataConn != nil {
186+ conn .dataConn .Write (data )
187+ conn .dataConn .Close ()
188+ conn .dataConn = nil
189189 }
190190 message := "Closing data connection, sent " + strconv .Itoa (bytes ) + " bytes"
191- Conn .writeMessage (226 , message )
191+ conn .writeMessage (226 , message )
192192}
193193
194- func (Conn * Conn ) sendOutofBandDataWriter (data io.ReadCloser ) error {
195- Conn .lastFilePos = 0
196- bytes , err := io .Copy (Conn .dataConn , data )
194+ func (conn * Conn ) sendOutofBandDataWriter (data io.ReadCloser ) error {
195+ conn .lastFilePos = 0
196+ bytes , err := io .Copy (conn .dataConn , data )
197197 if err != nil {
198- Conn .dataConn .Close ()
199- Conn .dataConn = nil
198+ conn .dataConn .Close ()
199+ conn .dataConn = nil
200200 return err
201201 }
202202 message := "Closing data connection, sent " + strconv .Itoa (int (bytes )) + " bytes"
203- Conn .writeMessage (226 , message )
204- Conn .dataConn .Close ()
205- Conn .dataConn = nil
203+ conn .writeMessage (226 , message )
204+ conn .dataConn .Close ()
205+ conn .dataConn = nil
206206
207207 return nil
208208}
0 commit comments