summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-06-04 20:13:03 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-06-04 20:13:03 +0000
commitb20e2a5a26d3c9bbbea0dbea71227085bb8a135a (patch)
treed37a43a33c528c0c8240263a2ad0d0ce50e4bc55 /apps
parent77a8ce12ae20be575adaf975d881da56f4b3b6dc (diff)
downloadpx4-nuttx-b20e2a5a26d3c9bbbea0dbea71227085bb8a135a.tar.gz
px4-nuttx-b20e2a5a26d3c9bbbea0dbea71227085bb8a135a.tar.bz2
px4-nuttx-b20e2a5a26d3c9bbbea0dbea71227085bb8a135a.zip
Fix more FTP bugs
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3668 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps')
-rw-r--r--apps/examples/README.txt8
-rw-r--r--apps/netutils/ftpc/ftpc_getfile.c10
-rw-r--r--apps/netutils/ftpc/ftpc_socket.c61
3 files changed, 46 insertions, 33 deletions
diff --git a/apps/examples/README.txt b/apps/examples/README.txt
index a67d9ad04..5a9d050b4 100644
--- a/apps/examples/README.txt
+++ b/apps/examples/README.txt
@@ -60,9 +60,11 @@ examples/ftpc
an example, your configration could have different mass storage devices,
mount paths, and FTP directories:
- mount -t vfat /dev/mmcsd0 /tmp # Mount the SD card at /tmp
- cd /tmp # cd into the /tmp directory
- ftpc xx.xx.xx.xx[:pp] # Start the FTP client
+ nsh> mount -t vfat /dev/mmcsd0 /tmp # Mount the SD card at /tmp
+ nsh> cd /tmp # cd into the /tmp directory
+ 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
optional port number.
diff --git a/apps/netutils/ftpc/ftpc_getfile.c b/apps/netutils/ftpc/ftpc_getfile.c
index 30595d942..846a1e1db 100644
--- a/apps/netutils/ftpc/ftpc_getfile.c
+++ b/apps/netutils/ftpc/ftpc_getfile.c
@@ -149,13 +149,15 @@ static int ftpc_recvinit(struct ftpc_session_s *session, FAR const char *path,
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));
if (ret != OK)
- {
- ndbg("Data connection not accepted\n");
- }
+ {
+ ndbg("Data connection not accepted\n");
+ }
return ret;
}
diff --git a/apps/netutils/ftpc/ftpc_socket.c b/apps/netutils/ftpc/ftpc_socket.c
index 6d917cf36..bfa8ec7c1 100644
--- a/apps/netutils/ftpc/ftpc_socket.c
+++ b/apps/netutils/ftpc/ftpc_socket.c
@@ -37,6 +37,7 @@
* Included Files
****************************************************************************/
+#include "ftpc_config.h"
#include <sys/socket.h>
#include <stdlib.h>
@@ -208,7 +209,8 @@ void ftpc_sockcopy(FAR struct ftpc_socket_s *dest,
* Name: ftpc_sockaccept
*
* 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;
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
* 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
@@ -246,6 +238,17 @@ int ftpc_sockaccept(struct ftpc_socket_s *sock, bool 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);
sock->sd = accept(sock->sd, &addr, &addrlen);
if (sock->sd == -1)
@@ -255,26 +258,32 @@ int ftpc_sockaccept(struct ftpc_socket_s *sock, bool passive)
}
memcpy(&sock->laddr, &addr, sizeof(sock->laddr));
- }
- /* Create in/out C buffer I/O streams on the data channel. First, create
- * the incoming buffered stream.
- */
+ /* Create in/out C buffer I/O streams on the data channel. First,
+ * create the incoming buffered stream.
+ */
- sock->instream = fdopen(sock->sd, "r");
- if (!sock->instream)
- {
- ndbg("fdopen() failed: %d\n", errno);
- goto errout_with_sd;
- }
+ sock->instream = fdopen(sock->sd, "r");
+ if (!sock->instream)
+ {
+ ndbg("fdopen() failed: %d\n", errno);
+ goto errout_with_sd;
+ }
- /* Create the outgoing stream */
+ /* Create the outgoing stream */
- sock->outstream = fdopen(sock->sd, "w");
- if (!sock->outstream)
+ sock->outstream = fdopen(sock->sd, "w");
+ if (!sock->outstream)
+ {
+ ndbg("fdopen() failed: %d\n", errno);
+ goto errout_with_instream;
+ }
+ }
+ else
{
- ndbg("fdopen() failed: %d\n", errno);
- goto errout_with_instream;
+ /* Should already be set up from ftpc_sockinit() call */
+
+ DEBUGASSERT(sock->sd >= 0 && sock->instream && sock->outstream);
}
return OK;