Fix more FTP bugs
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3668 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
199695630e
commit
a414a831a3
@ -60,9 +60,11 @@ examples/ftpc
|
|||||||
an example, your configration could have different mass storage devices,
|
an example, your configration could have different mass storage devices,
|
||||||
mount paths, and FTP directories:
|
mount paths, and FTP directories:
|
||||||
|
|
||||||
mount -t vfat /dev/mmcsd0 /tmp # Mount the SD card at /tmp
|
nsh> mount -t vfat /dev/mmcsd0 /tmp # Mount the SD card at /tmp
|
||||||
cd /tmp # cd into the /tmp directory
|
nsh> cd /tmp # cd into the /tmp directory
|
||||||
ftpc xx.xx.xx.xx[:pp] # Start the FTP client
|
nsh> ftpc xx.xx.xx.xx[:pp] # Start the FTP client
|
||||||
|
nfc> login <name> <password> # Log into the FTP server
|
||||||
|
nfc> help # See a list of FTP commands
|
||||||
|
|
||||||
where xx.xx.xx.xx is the IP address of the FTP server and pp is an
|
where xx.xx.xx.xx is the IP address of the FTP server and pp is an
|
||||||
optional port number.
|
optional port number.
|
||||||
|
@ -149,7 +149,9 @@ static int ftpc_recvinit(struct ftpc_session_s *session, FAR const char *path,
|
|||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Accept a connection on the data socket */
|
/* Accept a connection on the data socket (unless passive mode then the
|
||||||
|
* function does nothing).
|
||||||
|
*/
|
||||||
|
|
||||||
ret = ftpc_sockaccept(&session->data, FTPC_IS_PASSIVE(session));
|
ret = ftpc_sockaccept(&session->data, FTPC_IS_PASSIVE(session));
|
||||||
if (ret != OK)
|
if (ret != OK)
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
* Included Files
|
* Included Files
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "ftpc_config.h"
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -208,7 +209,8 @@ void ftpc_sockcopy(FAR struct ftpc_socket_s *dest,
|
|||||||
* Name: ftpc_sockaccept
|
* Name: ftpc_sockaccept
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Accept a connection from the server.
|
* Accept a connection on the data socket (unless passive mode then this
|
||||||
|
* function does nothing).
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
@ -217,16 +219,6 @@ int ftpc_sockaccept(struct ftpc_socket_s *sock, bool passive)
|
|||||||
struct sockaddr addr;
|
struct sockaddr addr;
|
||||||
socklen_t addrlen;
|
socklen_t addrlen;
|
||||||
|
|
||||||
/* Any previous socket should have been uninitialized (0) or explicitly
|
|
||||||
* closed (-1). But the path to this function may include a call to
|
|
||||||
* ftpc_sockinit().
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (sock->sd > 0)
|
|
||||||
{
|
|
||||||
ftpc_sockclose(sock);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* In active mode FTP the client connects from a random port (N>1023) to the
|
/* 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
|
* FTP server's command port, port 21. Then, the client starts listening to
|
||||||
* port N+1 and sends the FTP command PORT N+1 to the FTP server. The server
|
* port N+1 and sends the FTP command PORT N+1 to the FTP server. The server
|
||||||
@ -246,6 +238,17 @@ int ftpc_sockaccept(struct ftpc_socket_s *sock, bool passive)
|
|||||||
|
|
||||||
if (!passive)
|
if (!passive)
|
||||||
{
|
{
|
||||||
|
/* Any previous socket should have been uninitialized (0) or explicitly
|
||||||
|
* closed (-1). But the path to this function may include a call to
|
||||||
|
* ftpc_sockinit(). If so... close that socket and call accept to
|
||||||
|
* get a new one.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (sock->sd > 0)
|
||||||
|
{
|
||||||
|
ftpc_sockclose(sock);
|
||||||
|
}
|
||||||
|
|
||||||
addrlen = sizeof(addr);
|
addrlen = sizeof(addr);
|
||||||
sock->sd = accept(sock->sd, &addr, &addrlen);
|
sock->sd = accept(sock->sd, &addr, &addrlen);
|
||||||
if (sock->sd == -1)
|
if (sock->sd == -1)
|
||||||
@ -255,10 +258,9 @@ int ftpc_sockaccept(struct ftpc_socket_s *sock, bool passive)
|
|||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&sock->laddr, &addr, sizeof(sock->laddr));
|
memcpy(&sock->laddr, &addr, sizeof(sock->laddr));
|
||||||
}
|
|
||||||
|
|
||||||
/* Create in/out C buffer I/O streams on the data channel. First, create
|
/* Create in/out C buffer I/O streams on the data channel. First,
|
||||||
* the incoming buffered stream.
|
* create the incoming buffered stream.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sock->instream = fdopen(sock->sd, "r");
|
sock->instream = fdopen(sock->sd, "r");
|
||||||
@ -276,6 +278,13 @@ int ftpc_sockaccept(struct ftpc_socket_s *sock, bool passive)
|
|||||||
ndbg("fdopen() failed: %d\n", errno);
|
ndbg("fdopen() failed: %d\n", errno);
|
||||||
goto errout_with_instream;
|
goto errout_with_instream;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Should already be set up from ftpc_sockinit() call */
|
||||||
|
|
||||||
|
DEBUGASSERT(sock->sd >= 0 && sock->instream && sock->outstream);
|
||||||
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user