delete remote ftp directory

Hi,

I would like to be able to delete a directory on an ftp server! There sounds so easy but it’s giving me so much grief!!!

I’ve been using ncftp to download files from an ftp site.

do shell script "ncftpget -R -u username -p password ftp.address " & dest_folder & space & "path/to/directory/" & quoted_file

If quoted_file is a file then it will be downloaded to the dest_folder and then be deleted from the ftp server, however if quoted_file is a directory it will download the directory and its contents to the dest_folder and delete all of the items within the directory on the ftp sever but will still leave the empty directory behind. I think this is a limitation of the ncftp command. To work around this problem I thought I could log back into the ftp and then rmdir

 ncftp -u username -p password [url=ftp://ftp.address.com]ftp.address.com[/url]

then

rmdir /path/to/directory/the_directory

This works within Terminal as it’s two separate commands. I tried concatenating the two commands like

ncftp -u username -p password [url=ftp://ftp.address.com]ftp.address.com[/url]; rmdir /path/to/directory/the_directory

but this doesn’t work either, it only logs in and doesn’t carry out the second command. Running out of ideas, I decided to try scripting the two commands in Terminal

tell application "Terminal"
						activate
						do script "ncftp -u username -p password [url=ftp://ftp.address.com]ftp.address.com[/url]" in window 1
						delay 10
						do script "rmdir path/to/directory/" & quoted form of this_item in window 1
						delay 10
						quit saving no
					end tell

This does work but only in Terminal version 2.0.2 (Leopard) and I want to run the finished code on a machine running Tiger and Terminal version 1.5.1. I have exausted all my limited shell commands knowledge and run out of ideas. If anybody has any ideas of how I can delete a directory on an ftp site I would be most grateful. If possible I would like to do this using the do shell script command.
Many Thanks,
Nik

Hi,

I don’t know ncftpget, but what is the advantage over cURL?
You can do almost everything with cURL e.g. remove a directory on the server


do shell script "curl -Q 'RMD path/to/folder' -u user:pass [url=ftp://ftp.myServer.com]ftp.myServer.com[/url]"

or a file


do shell script "curl -Q 'DELE path/to/file' -u user:pass [url=ftp://ftp.myServer.com]ftp.myServer.com[/url]"

Hi Stefan,

I have only ever used cURL to upload files before and so was unsure of any commands and properties, I found ncftp quite easy to understand so went down that route. I just tried

do shell script "curl -Q 'RMD path/to/folder' -u user:pass [url=ftp://ftp.myServer.com]ftp.myServer.com[/url]"

and got this error message

not sure what this means, can you shed any light?
Many Thanks for your reply,

Nik

I have no idea,

I just have googled the commands and tested them quickly with my server.
Both lines worked successfully

Ok,
I’ll persist with the commands and see where I get!
Thanks again,
Nik

Hi Stefan,

Just to update you, your cURL command worked, I turned on the verbose logging (-v) and because the directory was not empty it couldn’t delete it. My ncftp script removes the files from the directory once they’ve been downloaded so I simply have to add the cURL commands after the files have been downloaded and the directory is deleted.

Thanks once again for your help,
Nik

This would be a useful information for me to know as well, however I simply want to delete files from an FTP. My ultimate plan would be to delte files over 30 days from an ftp. But prior to getting over my head, I am trying to learn some basics and just delete a given file from an FTP server?

I am not sure why my script isn’t working:

set filevar to ""

tell application "Finder"
	display dialog "Enter file name:" default answer filevar buttons ("Delete File") default button 1
	set filevar to text returned of the result
end tell


do shell script "curl -Q " & quoted form of ("DELE /" & filevar) & " ftp://admin:password@10.10.10.1"

The AppleScript Error I receive is:
" % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0
curl: (21) QUOT command failed with 550"

FWIW, my admin/password is something else other than what is in my script. I was able to upload a file successfully using this script:

set somefile to ((path to desktop as text) & "TestFile.jpg")

property ftpURL : "ftp://admin:password@10.10.10.1"

tell application "URL Access Scripting" to upload somefile to ftpURL replacing yes without binhexing