Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

#!/bin/sh

HOST='www.ftpserver.com'
USER='username'
PASSWD='password'

ftp -n $HOST <<END_SCRIPT
user ${USER} ${PASSWD}


for i in {ls}
do
 echo "$i"
done

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

2 Answers 2

up vote 3 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.