[wplug] Off-the-wall Question on FTP

Chester R. Hosey chosey at nauticom.net
Wed Mar 8 11:58:22 EST 2006


Diana A. Clarion wrote:
> On Tue, Mar 07, 2006 at 09:06:29AM -0500, Rob Knapp wrote:
> 
>>On Tue, 2006-03-07 at 08:39 -0500, Eric Cooper wrote:
>>
>>>On Tue, Mar 07, 2006 at 12:14:38AM -0500, Diana A. Clarion wrote:
>>>
>>>>I notice that one can attempt to retrieve a
>>>>file several directories removed from the remote CWD, but if one does not
>>>>specify a local file name and a similar tree does not exist locally, the
>>>>client goes *boof* (technical term).
>>>
>>>Broken client, I'd say:
>>
>>I'd agree.  A few years ago, I wrote a very small ftp client library for
>>python.  (ftplib having to many dependencies for our needs.)
>>
> 
> Ah, thanks.  That's what I was looking for.  Call me whatever you want to call
> me, but I have a hard time wading through many of the specifications
> (especially POSIX).  I likely forgot to mention, but the client in question is
> the one that comes with FreeBSD...
> 
> DAC

If you're interested, it wouldn't be hard to revise the code slightly to
change this behavior, either by attempting to create the directory first
or by simply stripping the directory portion of the filename prior to
processing. A description of causing the latter behavior follows, if
you're interested. If not, no biggie. Personally, I'd probably just seek
another client, but sometimes it's fun to play.

I'm pretty sure BSD generally defaults to lukemftp, and the source
filenames match the Debian distribution of lukemftp, which I examined
for the following comments.

Check out the getit function in cmds.c (I'm not sure where it is in the
source tree, but it shouldn't be that hard to track down). There's a
line that reads:

	locfile = olocfile;

Declare a new "char *tmpfn" at the top of the function, and change the
above line to read:

	tmpfn = strdup(olocfile);
	locfile = basename(tmpfn);

To the end of the function (after the "freegetit" label), add:

	(void)free(tmpfn);

Yes, I dislike the case to void, but it matches the style of the rest of
the program. Consistency makes code easier to read, so it's a good
habit. Four lines of code, a recompile, and you no longer have attempts
to create files in invalid directories.

Changing the behavior to attempting to create the directory first is
similarly easy. If you're interested and would like some help, feel free
to shoot me an email off-list.

Chet



More information about the wplug mailing list