More FTP fixes

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3666 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2011-06-03 22:53:36 +00:00
parent da50c819f9
commit 4287df5472
8 changed files with 54 additions and 24 deletions

View File

@ -276,7 +276,7 @@ int cmd_rls(SESSION handle, int argc, char **argv)
int cmd_rget(SESSION handle, int argc, char **argv)
{
FAR const char *lname = argv[1];
FAR const char *lname = NULL;
if (argc > 2)
{
@ -291,7 +291,7 @@ int cmd_rget(SESSION handle, int argc, char **argv)
int cmd_rput(SESSION handle, int argc, char **argv)
{
FAR const char *rname = argv[1];
FAR const char *rname = NULL;
if (argc > 2)
{

View File

@ -151,7 +151,7 @@ static int ftpc_recvinit(struct ftpc_session_s *session, FAR const char *path,
/* Accept a connection on the data socket */
ret = ftpc_sockaccept(&session->data, "r", FTPC_IS_PASSIVE(session));
ret = ftpc_sockaccept(&session->data, FTPC_IS_PASSIVE(session));
if (ret != OK)
{
ndbg("data connection not accepted\n");
@ -274,6 +274,19 @@ int ftpc_getfile(SESSION handle, FAR const char *rname, FAR const char *lname,
off_t offset;
int ret;
/* Don't call this with a NULL remote file name */
DEBUGASSERT(rname);
/* If the local name is not specified, then it is assumed to the same as
* the remote file name.
*/
if (!lname)
{
lname = rname;
}
/* Get the full path to the local file */
abslpath = ftpc_abslpath(session, lname);

View File

@ -246,8 +246,7 @@ EXTERN int ftpc_sockconnect(FAR struct ftpc_socket_s *sock,
FAR struct sockaddr_in *addr);
EXTERN int ftpc_sockgetsockname(FAR struct ftpc_socket_s *sock,
FAR struct sockaddr_in *sa);
EXTERN int ftpc_sockaccept(FAR struct ftpc_socket_s *sock,
FAR const char *mode, bool passive);
EXTERN int ftpc_sockaccept(FAR struct ftpc_socket_s *sock, bool passive);
EXTERN int ftpc_socklisten(FAR struct ftpc_socket_s *sock);
EXTERN void ftpc_sockcopy(FAR struct ftpc_socket_s *dest,
FAR const struct ftpc_socket_s *src);

View File

@ -201,7 +201,7 @@ static int ftpc_recvdir(FAR struct ftpc_session_s *session,
/* Accept the connection from the server */
ret = ftpc_sockaccept(&session->data, "r", FTPC_IS_PASSIVE(session));
ret = ftpc_sockaccept(&session->data, FTPC_IS_PASSIVE(session));
if (ret != OK)
{
ndbg("ftpc_sockaccept() failed: %d\n", errno);

View File

@ -340,7 +340,7 @@ static int ftpc_sendfile(struct ftpc_session_s *session, const char *path,
* with a mark.
*/
ret = ftpc_sockaccept(&session->data, "w", FTPC_IS_PASSIVE(session));
ret = ftpc_sockaccept(&session->data, FTPC_IS_PASSIVE(session));
if (ret != OK)
{
ndbg("Data connection not accepted\n");
@ -388,6 +388,19 @@ int ftp_putfile(SESSION handle, const char *lname, const char *rname,
FILE *finstream;
int ret;
/* Don't call this with a NULL local file name */
DEBUGASSERT(lname);
/* If the remote name is not specified, then it is assumed to the same as
* the local file name.
*/
if (!rname)
{
rname = lname;
}
/* Get the full path to the local file */
abslpath = ftpc_abslpath(session, lname);

View File

@ -212,16 +212,20 @@ void ftpc_sockcopy(FAR struct ftpc_socket_s *dest,
*
****************************************************************************/
int ftpc_sockaccept(struct ftpc_socket_s *sock, const char *mode, bool passive)
int ftpc_sockaccept(struct ftpc_socket_s *sock, bool passive)
{
struct sockaddr addr;
socklen_t addrlen;
/* Any previous socket should have been uninitialized (0) or explicitly
* closed (-1).
* closed (-1). But the path to this function may include a call to
* ftpc_sockinit().
*/
DEBUGASSERT(sock->sd == 0 || sock->sd == -1);
if (sock->sd > 0)
{
ftpc_sockclose(sock);
}
/* In active mode FTP the client connects from a random port (N>1023) to the
* FTP server's command port, port 21. Then, the client starts listening to
@ -249,6 +253,7 @@ int ftpc_sockaccept(struct ftpc_socket_s *sock, const char *mode, bool passive)
ndbg("accept() failed: %d\n", errno);
return ERROR;
}
memcpy(&sock->laddr, &addr, sizeof(sock->laddr));
}
@ -256,7 +261,7 @@ int ftpc_sockaccept(struct ftpc_socket_s *sock, const char *mode, bool passive)
* the incoming buffered stream.
*/
sock->instream = fdopen(sock->sd, mode);
sock->instream = fdopen(sock->sd, "r");
if (!sock->instream)
{
ndbg("fdopen() failed: %d\n", errno);
@ -265,7 +270,7 @@ int ftpc_sockaccept(struct ftpc_socket_s *sock, const char *mode, bool passive)
/* Create the outgoing stream */
sock->outstream = fdopen(sock->sd, mode);
sock->outstream = fdopen(sock->sd, "w");
if (!sock->outstream)
{
ndbg("fdopen() failed: %d\n", errno);

View File

@ -285,21 +285,21 @@ int ftpc_xfrinit(FAR struct ftpc_session_s *session)
ndbg("ftp_pasvmode() failed: %d\n", errno);
goto errout_with_data;
}
}
/* Configure the data socket */
/* Configure the data socket */
ftpc_sockgetsockname(&session->cmd, &addr);
memcpy(&addr.sin_addr, addrport, (size_t)4);
memcpy(&addr.sin_port, addrport+4, (size_t)2);
ftpc_sockgetsockname(&session->cmd, &addr);
memcpy(&addr.sin_addr, addrport, (size_t)4);
memcpy(&addr.sin_port, addrport+4, (size_t)2);
/* Connect the data socket */
/* Connect the data socket */
ret = ftpc_sockconnect(&session->data, &addr);
if (ret < 0)
{
ndbg("ftpc_sockconnect() failed: %d\n", errno);
goto errout_with_data;
ret = ftpc_sockconnect(&session->data, &addr);
if (ret < 0)
{
ndbg("ftpc_sockconnect() failed: %d\n", errno);
goto errout_with_data;
}
}
else
{

View File

@ -431,7 +431,7 @@ static int cmd_help(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
/* List the set of available built-in commands */
#ifdef CONFIG_NSH_BUILTIN_APPS
nsh_output(vtbl, "\nBuiltin Apps: ");
nsh_output(vtbl, "\nBuiltin Apps:\n");
for (i = 0; (name = namedapp_getname(i)) != NULL; i++)
{
nsh_output(vtbl, " %s\n", name);