Possible Duplicate:
How to delete the oldest file over FTP using CURL?

I need to connect to a remote server using a bash script and then delete all files within the directory that are older than 7 days. I'm trying to do this with a for loop within the FTP remote server and I get an error.



user ${USER} ${PASSWD}

for i in {ls}
 echo "$i"

exit 0

The error I get is

We only support non-print format, sorry.
?Invalid command
?Invalid command

Any pointers will help

marked as duplicate by Gilles, jasonwryan, Renan, Mat, Caleb Nov 16 '12 at 9:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Not sure if it's "The Right Way", but you could use FTPFS and any Bash script you like. – sr_ Nov 14 '12 at 19:11
  • 1
    lftp can run in batch mode, as in lftp -u username,password ftp://server -e "ls" – charlesbridge Nov 14 '12 at 21:43

Either rewrite your script in: Perl, PHP or Python, as they all offer API's for FTP, else have a look at using expect. There are several tutorials around.


The FTP protocol has a very limited set of commands. You cannot use shell scripting with a ftp connection. If you want to do that, use telnet or ssh.

Not the answer you're looking for? Browse other questions tagged or ask your own question.