+ net_Close( p_sys->fd_cmd );
+ return -1;
+ }
+
+ if( ftp_ReadCommand( p_access, p_sys, NULL, NULL ) == 2 )
+ {
+ if( net_GetPeerAddress( p_sys->fd_cmd, p_sys->sz_epsv_ip, NULL ) )
+ {
+ net_Close( p_sys->fd_cmd );
+ return -1;
+ }
+ }
+ else
+ {
+ /* If ESPV ALL fails, we fallback to PASV.
+ * We have to restart the connection in case there is a NAT that
+ * understands EPSV ALL in the way, and hence won't allow PASV on
+ * the initial connection.
+ */
+ msg_Info( p_access, "FTP Extended passive mode disabled" );
+ net_Close( p_sys->fd_cmd );
+
+ if( Login( p_access, p_sys ) )
+ {
+ net_Close( p_sys->fd_cmd );
+ return -1;
+ }
+ }
+
+ /* check binary mode support */
+ if( ftp_SendCommand( p_access, p_sys, "TYPE I" ) < 0 ||
+ ftp_ReadCommand( p_access, p_sys, NULL, NULL ) != 2 )
+ {
+ msg_Err( p_access, "cannot set binary transfer mode" );
+ net_Close( p_sys->fd_cmd );