summaryrefslogtreecommitdiff
path: root/apps/netutils/ftpc/ftpc_getfile.c
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-06-03 20:27:30 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-06-03 20:27:30 +0000
commit92fd8f5221ca528c2def13897c712d558adf1675 (patch)
tree0c9d63fe3408864b46597a4eb1c20eace2ffc783 /apps/netutils/ftpc/ftpc_getfile.c
parent90e92459a9c7a33fb8a005f87ec3f512b760c487 (diff)
downloadnuttx-92fd8f5221ca528c2def13897c712d558adf1675.tar.gz
nuttx-92fd8f5221ca528c2def13897c712d558adf1675.tar.bz2
nuttx-92fd8f5221ca528c2def13897c712d558adf1675.zip
More FTP bugfixes
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3665 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/netutils/ftpc/ftpc_getfile.c')
-rw-r--r--apps/netutils/ftpc/ftpc_getfile.c65
1 files changed, 45 insertions, 20 deletions
diff --git a/apps/netutils/ftpc/ftpc_getfile.c b/apps/netutils/ftpc/ftpc_getfile.c
index e9816e5b4..bf9fc69ea 100644
--- a/apps/netutils/ftpc/ftpc_getfile.c
+++ b/apps/netutils/ftpc/ftpc_getfile.c
@@ -270,20 +270,30 @@ int ftpc_getfile(SESSION handle, FAR const char *rname, FAR const char *lname,
FAR struct ftpc_session_s *session = (FAR struct ftpc_session_s *)handle;
struct stat statbuf;
FILE *loutstream;
+ FAR char *abslpath;
off_t offset;
int ret;
+ /* Get the full path to the local file */
+
+ abslpath = ftpc_abslpath(session, lname);
+ if (!abslpath)
+ {
+ ndbg("ftpc_abslpath(%s) failed: %d\n", errno);
+ goto errout;
+ }
+
/* Get information about the local file */
- ret = stat(lname, &statbuf);
+ ret = stat(abslpath, &statbuf);
if (ret == 0)
{
/* It already exists. Is it a directory? */
if (S_ISDIR(statbuf.st_mode))
{
- ndbg("'%s' is a directory\n", lname);
- return ERROR;
+ ndbg("'%s' is a directory\n", abslpath);
+ goto errout_with_abspath;
}
}
@@ -292,8 +302,8 @@ int ftpc_getfile(SESSION handle, FAR const char *rname, FAR const char *lname,
#ifdef S_IWRITE
if (!(statbuf.st_mode & S_IWRITE))
{
- ndbg("'%s' permission denied\n", lname);
- return ERROR;
+ ndbg("'%s' permission denied\n", abslpath);
+ goto errout_with_abspath;
}
#endif
@@ -316,36 +326,33 @@ int ftpc_getfile(SESSION handle, FAR const char *rname, FAR const char *lname,
if (ret != OK)
{
ndbg("ftpc_recvinit failed\n");
- return ERROR;
+ goto errout_with_abspath;
}
- loutstream = fopen(lname, (offset > 0 || (how == FTPC_GET_APPEND)) ? "a" : "w");
+ loutstream = fopen(abslpath, (offset > 0 || (how == FTPC_GET_APPEND)) ? "a" : "w");
if (!loutstream)
{
ndbg("fopen failed: %d\n", errno);
- session->offset = 0;
- return ERROR;
+ goto errout_with_abspath;
}
+ /* Save the new local and remote file names */
+
+ free(session->rname);
+ free(session->lname);
+ session->rname = strdup(rname);
+ session->lname = abslpath;
+
if (offset > 0)
{
ret = fseek(loutstream, offset, SEEK_SET);
if (ret != OK)
{
ndbg("fseek failed: %d\n", errno);
- fclose(loutstream);
- session->offset = 0;
- return ERROR;
+ goto errout_with_outstream;
}
}
- /* Save the new local and remote file names */
-
- free(session->rname);
- free(session->lname);
- session->rname = strdup(rname);
- session->lname = strdup(lname);
-
/* And receive the new file data */
if (xfrmode == FTPC_XFRMODE_ASCII)
@@ -364,8 +371,26 @@ int ftpc_getfile(SESSION handle, FAR const char *rname, FAR const char *lname,
fptc_getreply(session);
}
+ /* On success, the last rname and lname are retained for debug purpose */
+
+ if (ret == OK && !FTPC_INTERRUPTED(session))
+ {
+ fclose(loutstream);
+ return OK;
+ }
+
+ /* Various error exits */
+
+errout_with_outstream:
fclose(loutstream);
- return (ret == OK && !FTPC_INTERRUPTED(session)) ? OK : ERROR;
+ free(session->rname);
+ session->rname = NULL;
+ session->lname = NULL;
+errout_with_abspath:
+ free(abslpath);
+ session->offset = 0;
+errout:
+ return ERROR;
}
/****************************************************************************