FTP and applescript

Once you have opened a location of a url

Once the domain is mounted on Desktop
How does one move local files to domain?
How does one remove files from domain?
via applescript? :rolleyes:

It all depends on what protocol helper (presumably, in this case, ftp client) you’re using.

If you’re using the Finder, you’re out of luck - AFAIK the Finder always mounts FTP sites as read-only.

If you’re using a traditional FTP client such as Fetch or Interarchy, each have their own dictionaries for uploading and manipulating files on the server.

What are you using?

I use Interarchy, but I thought there might be some applescript that can help me get around that… I guess not eh. :frowning:

If there is a way this would be the forum to do it in… :slight_smile:

Using “URL Access Scripting”, I think it’s possible to upload and download files but I don’t think it’s possible to delete them from a remote server.

With that said, I was always under the impression that if a volume is mounted on the desktop, the Finder could manipulate the files, as long as permissions allow it. If so, and I have no experience with this, you could script the Finder to work on the mounted volume in much the same way that it works on local volumes/disks.

Of course, if I’m wrong, it wouldn’t be the first time. :stuck_out_tongue:

The command-line utility curl is VERY powerful. You can download/upload via FTP, or HTTP, and do many other things. You can send FTP commands of many types. Check it out - it’s built into Mac OS X since version 10.1. One thing to note if making many consecutive connections to an FTP server - you may need to send an explicit disconnect command so the FTP server doesn’t exceed its simultaneous connections. I saw this once when I was uploading a buunch of files one at a time, and the FTP server waited a while to drop a completed connection.

Krioni, that is totally brilliant! Thanks this works great for uploading… now if we could remove files that way! :slight_smile:

I read in the curl man pages the following. You can send FTP commands directly to the server using curl’s --quote option. You’ll have to look up what the command you need to send is, and find out whether your FTP server supports it. Here’s what the man pages say:

-Q/--quote <comand>
  (FTP)  Send  an arbitrary command to the remote FTP
  server, by using the QUOTE command of  the  server.
  Not  all  servers support this command, and the set
  of QUOTE commands are server specific!  Quote  com-
  mands are sent BEFORE the transfer is taking place.
  To make commands  take  place  after  a  successful
  transfer,  prefix  them  with  a  dash '-'. You may
  specify any amount of commands to be run before and
  after  the  transfer. If the server returns failure
  for one of the commands, the entire operation  will
  be aborted.
  This option can be used multiple times.

So, you may be able to send a command to ‘del somedirectory/yourfile.txt’

You’ll have to do some research, but I think it is possible. :slight_smile:

here’s a Fetch ftp handler. It’s setup to send the same file to multiple site urls. It tries to delete the existing file at the url if the server has the name of “classpag”. This is not perfect but gives a good example of what you’re looking for… :?
On success the routine returns a boolean “true” so that I can delete the original file elsewhere in a script…

on fetchcopy(filetoprocess)
set trashit to false
set curdfurl to item 2 of filetoprocess
set myfile to item 1 of filetoprocess
tell application “Fetch 4.0.3”
with timeout of 600 seconds
if “classpag” is in curdfurl then
set fullurl to curdfurl & (name of myfile)
delete url fullurl
end if
put into url curdfurl item myfile binary format Raw Data text format Raw Data
close transfer window 1
set trashit to true
on error errMsg
display dialog errMsg & "
Filename " & myfile giving up after 2
close transfer window 1
end try
end try
end timeout
end tell
return trashit
end fetchcopy

(sorry about the formatting…)