[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Capturing output from ftp

Ian Melnick said:
> Hello all,
> So I followed directions from a previous message, but I've run into a
> different problem.
> I need to get the size of a given file with the ftp program, so I tried
> something like this:
> ftp server <<END
> size filename
> quit
> The problem is, when it returns the information, it doesn't seem to be
> getting sent to standard out, or whatever you call it. If I do nlist or
> ls instead of size, even modtime, I can set that output to a variable.
> But in the case of size, it seems to return as a server message (with a
> special number before it, like the lines you get when you first log on,
> while tranferring a file, etc), and I need to somehow capture this
> information into a variable. How do I do this?

The "special number" is a reply code, as specified in the FTP protocol.

Whether something gets sent to standard output may depend on the way the
ftp client app is being interacted with. The program can detect that it is
being run by a script so it doesn't output a lot of the interactive data -
note that you don't get the standard login printouts either, as in the
"Connected to ..." and "221-You have transferred 0 bytes in 0 files." or
whatever. Some command output obviously counts as valid and some doesn't
from what you say.

You *can* get what you want by putting "verbose" into your script before
and after the "size ..." command, and using awk to cut out the number you

CAVEAT: if you're going to be doing a lot of this interacting with remote
servers on anything more than a purely superficial level, you may find it
more beneficial to look at "expect", which is designed for this sort of


Reply to: