How to store results of ls in ftp?

Hi,
I want to store the results of running ls in a directory on a remote host using ftp.

For example,

#!/usr/bin/ksh
 
ftp -n hostx <<EOF
user username password
 
ls /tmp/RandomFiles.*
 
#I need to put the results of that ls command into some file, so I can get the last file in that list

The ultimate goal is to get the LAST RandomFiles file. Since I can't just tail -1 in ftp, I'm trying to store the results of ls in a file and then get the last entry from that file, then finally ftp that exact entry from the host again.

Redirection works in usual way...

ftp -n hostx <<EOF >> ftp_out.txt

thank you, sorry if the question was stupid, im very new to this..

---------- Post updated at 11:36 AM ---------- Previous update was at 11:28 AM ----------

Also, could you tell me how I can extract the file name from the last line of ftp_out.txt?

The last line of ftp_out.txt is:

-rw-r--r--   1 root       sys          42512 Jul 11 19:25 /tmp/RandomFile.0711

I need to get RandomFile.0711, then get that file using ftp from hostx.

Try...

$ cat ftp_out.txt
-rw-r--r--   1 root       sys          42512 Jul 11 19:25 /tmp/RandomFile.0711

$ set -- $(<ftp_out.txt)

$ basename ${!#}
RandomFile.0711

$