Running script on SFTP server, RMDIR and RM with wildcards

Im going insane trying to figure out what i consider a basic command on an SFTP server...

Im trying to download all files from a directory *done*
then remove all the files (and sometimes folders that contain files) i have downloaded on the remote directory...

the command i would normally use is rm -r *

Ive tried

rm -r *
rm *
rmdir *
rmdir -r *
rm -r * + rm * together
rmdir -r

im going insane... can someone put me out of my misery?

can anyone help with this?

---------- Post updated at 04:36 AM ---------- Previous update was at 04:24 AM ----------

Can i change the config on the sftp (ubuntu) server to enable removal of directories that contain files?

Im looking inside /etc/ssh/sshd_config not sure its the right place, really need a hand with this.

Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.

---------- Post updated at 11:52 ---------- Previous update was at 11:44 ----------

Taking a look at man sftp, I see two commands that would match:

     rm path
             Delete remote file specified by path.

     rmdir path
             Remove remote directory specified by path.

Both take no arguments. 'rm', in this case is only for files, while 'rmdir' is only for empty directories. Both are completely independent of the usual shell commands you might know, but are instead a part of the SSH server (sftp module).

You can probably remove all the files you fetched using 'rm *' (assuming you have the rights to do so), but you'll have to descend into each directory you got, remove the files, and then remove the directory.

A faster, but less portable, way would be to fetch the files using sftp, and then delete them using

ssh user@host 'cd /path/for/files; rm -r *'

Be advised, though, using 'rm -r' without care can easily result in a damaged system, and should be avoided where ever possible.