#define ACCOUNT_LONGTEXT N_("Account that will be " \
"used for the connection.")
-vlc_module_begin();
- set_shortname( "FTP" );
- set_description( N_("FTP input") );
- set_capability( "access", 0 );
- set_category( CAT_INPUT );
- set_subcategory( SUBCAT_INPUT_ACCESS );
+vlc_module_begin ()
+ set_shortname( "FTP" )
+ set_description( N_("FTP input") )
+ set_capability( "access", 0 )
+ set_category( CAT_INPUT )
+ set_subcategory( SUBCAT_INPUT_ACCESS )
add_integer( "ftp-caching", 2 * DEFAULT_PTS_DELAY / 1000, NULL,
CACHING_TEXT, CACHING_LONGTEXT, true );
add_string( "ftp-user", "anonymous", NULL, USER_TEXT, USER_LONGTEXT,
PASS_LONGTEXT, false );
add_string( "ftp-account", "anonymous", NULL, ACCOUNT_TEXT,
ACCOUNT_LONGTEXT, false );
- add_shortcut( "ftp" );
- set_callbacks( InOpen, InClose );
-
- add_submodule();
- set_shortname( "FTP" );
- set_description( N_("FTP upload output") );
- set_capability( "sout access", 0 );
- set_category( CAT_SOUT );
- set_subcategory( SUBCAT_SOUT_ACO );
- set_callbacks( OutOpen, OutClose );
-vlc_module_end();
+ add_shortcut( "ftp" )
+ set_callbacks( InOpen, InClose )
+
+ add_submodule ()
+ set_shortname( "FTP" )
+ set_description( N_("FTP upload output") )
+ set_capability( "sout access", 0 )
+ set_category( CAT_SOUT )
+ set_subcategory( SUBCAT_SOUT_ACO )
+ set_callbacks( OutOpen, OutClose )
+vlc_module_end ()
/*****************************************************************************
* Local prototypes
psz = strdup( p_sys->url.psz_username );
else
psz = var_CreateGetString( p_access, "ftp-user" );
+ if( !psz )
+ return -1;
if( ftp_SendCommand( p_access, p_sys, "USER %s", psz ) < 0 ||
ftp_ReadCommand( p_access, p_sys, &i_answer, NULL ) < 0 )
psz = strdup( p_sys->url.psz_password );
else
psz = var_CreateGetString( p_access, "ftp-pwd" );
+ if( !psz )
+ return -1;
if( ftp_SendCommand( p_access, p_sys, "PASS %s", psz ) < 0 ||
ftp_ReadCommand( p_access, p_sys, &i_answer, NULL ) < 0 )
static int parseURL( vlc_url_t *url, const char *path )
{
if( path == NULL )
- return -1;
+ return VLC_EGENERIC;
/* *** Parse URL and get server addr/port and path *** */
while( *path == '/' )
vlc_UrlParse( url, path, 0 );
if( url->psz_host == NULL || *url->psz_host == '\0' )
- return -1;
+ return VLC_EGENERIC;
if( url->i_port <= 0 )
url->i_port = IPPORT_FTP; /* default port */
/* FTP URLs are relative to user's default directory (RFC1738)
For absolute path use ftp://foo.bar//usr/local/etc/filename */
- if( *url->psz_path == '/' )
+ if( url->psz_path && *url->psz_path == '/' )
url->psz_path++;
- return 0;
+ return VLC_SUCCESS;
}
goto exit_error;
/* get size */
- if( ftp_SendCommand( p_this, p_sys, "SIZE %s", p_sys->url.psz_path ) < 0 ||
+ if( ftp_SendCommand( p_this, p_sys, "SIZE %s", p_sys->url.psz_path ? : "" ) < 0 ||
ftp_ReadCommand( p_this, p_sys, NULL, &psz_arg ) != 2 )
{
msg_Err( p_access, "cannot get file size" );
char *psz_cmd;
va_start( args, psz_fmt );
- vasprintf( &psz_cmd, psz_fmt, args );
+ if( vasprintf( &psz_cmd, psz_fmt, args ) == -1 )
+ return VLC_EGENERIC;
+
va_end( args );
msg_Dbg( p_access, "ftp_SendCommand:\"%s\"", psz_cmd);
+
if( net_Printf( VLC_OBJECT(p_access), p_sys->fd_cmd, NULL, "%s\r\n",
psz_cmd ) < 0 )
{
/* "1xx" message */
if( ftp_SendCommand( p_access, p_sys, "%s %s",
p_sys->out ? "STOR" : "RETR",
- p_sys->url.psz_path ) < 0 ||
+ p_sys->url.psz_path ?: "" ) < 0 ||
ftp_ReadCommand( p_access, p_sys, &i_answer, NULL ) > 2 )
{
msg_Err( p_access, "cannot retrieve file" );
if( p_sys->fd_data != -1 )
{
- int i_answer;
- ftp_ReadCommand( p_access, p_sys, &i_answer, NULL );
- if ( i_answer != 227 )
- /* If answer is from the previous command,
- * rathen that succesful ABOR - read next command */
- ftp_ReadCommand( p_access, p_sys, NULL, NULL );
-
net_Close( p_sys->fd_data );
p_sys->fd_data = -1;
+ /* Read the final response from RETR/STOR, i.e. 426 or 226 */
+ ftp_ReadCommand( p_access, p_sys, NULL, NULL );
}
+ /* Read the response from ABOR, i.e. 226 or 225 */
+ ftp_ReadCommand( p_access, p_sys, NULL, NULL );
return VLC_SUCCESS;
}