Use tls.DialWithDialer which does the handshake
tls.DialWithDialer also better handle special error cases
This commit is contained in:
		
							parent
							
								
									fed5bc26b7
								
							
						
					
					
						commit
						212daf295f
					
				
							
								
								
									
										26
									
								
								ftp.go
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								ftp.go
									
									
									
									
									
								
							| @ -520,11 +520,7 @@ func (c *ServerConn) openDataConn() (net.Conn, error) { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if c.options.tlsConfig != nil { | 	if c.options.tlsConfig != nil { | ||||||
| 		conn, err := c.options.dialer.Dial("tcp", addr) | 		return tls.DialWithDialer(&c.options.dialer, "tcp", addr, c.options.tlsConfig) | ||||||
| 		if err != nil { |  | ||||||
| 			return nil, err |  | ||||||
| 		} |  | ||||||
| 		return tls.Client(conn, c.options.tlsConfig), err |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return c.options.dialer.Dial("tcp", addr) | 	return c.options.dialer.Dial("tcp", addr) | ||||||
| @ -812,24 +808,8 @@ func (c *ServerConn) StorFrom(path string, r io.Reader, offset uint64) error { | |||||||
| 	// response otherwise if the failure is not due to a connection problem, | 	// response otherwise if the failure is not due to a connection problem, | ||||||
| 	// for example the server denied the upload for quota limits, we miss | 	// for example the server denied the upload for quota limits, we miss | ||||||
| 	// the response and we cannot use the connection to send other commands. | 	// the response and we cannot use the connection to send other commands. | ||||||
| 	// So we don't check io.Copy error and we return the error from | 	if _, err := io.Copy(conn, r); err != nil { | ||||||
| 	// ReadResponse so the user can see the real error | 		multierror.Append(errs, err) | ||||||
| 	var n int64 |  | ||||||
| 	n, err = io.Copy(conn, r) |  | ||||||
| 
 |  | ||||||
| 	// If we wrote no bytes but got no error, make sure we call |  | ||||||
| 	// tls.Handshake on the connection as it won't get called |  | ||||||
| 	// unless Write() is called. |  | ||||||
| 	// |  | ||||||
| 	// ProFTP doesn't like this and returns "Unable to build data |  | ||||||
| 	// connection: Operation not permitted" when trying to upload |  | ||||||
| 	// an empty file without this. |  | ||||||
| 	if n == 0 && err == nil { |  | ||||||
| 		if do, ok := conn.(interface{ Handshake() error }); ok { |  | ||||||
| 			if err := do.Handshake(); err != nil { |  | ||||||
| 				multierror.Append(errs, err) |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if err := conn.Close(); err != nil { | 	if err := conn.Close(); err != nil { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user