Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

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
lftp can run in batch mode, as in lftp -u username,password ftp://server -e "ls" – charlesbridge Nov 14 '12 at 21:43
up vote 4 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

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