Hello,
Is there anyway to list all files on a FTP server wiithout mounting it as a volume?
Thanks
Dallas
Hello,
Is there anyway to list all files on a FTP server wiithout mounting it as a volume?
Thanks
Dallas
Hi Dallas,
of course it is. curl is your friend
property ftpserverpath : "[url=ftp://ftp.myserver.com/path/to/dir/]ftp.myserver.com/path/to/dir/[/url]"
property server_username : "user"
property server_password : "¢¢¢¢"
set theDirectory to paragraphs of (do shell script "curl -l " & ftpserverpath & " -u " & server_username & ":" & server_password)
If you don’t want to mount it, you’ll probably have to use the UNIX shell. I’d probably use do shell script on wget with the appropriate options to not download anything, just make file listings. Then, you’ll at least have something to parse.
Hoped that gave you a bit of food for thought. With a bit more detail on precisely what you’re attempting to achieve, I may be able to whip up a sample for you. Are you simply trying to see if a particular file exists on the server (perhaps to check its size or modification time)? Are you trying to generate a listing of each and every file and its attributes on the server? Are you trying to make a listing of all .dmg files in a specific directory? There are lots of things you could be doing, and all of them have slightly different implementation details.
Edit: Heh. Stefan posted as I was typing. His sample gives an implementation using curl, for one possible scenario. More detail on what your end goal is would help, if his example doesn’t do it for you.
Hi Guys,
If you use curl it only lists the specfic directory choose. Is their an argument that will list all the files in the subdirectories as well. Similiar to the “ls -R” command.
What I am trying to do is mirror a local server with a ftp server.
When I mount the FTP server as volume it is readonly and will not show me any changes to the drive. I am trying to find the best way to get the file listing off of the FTP server without having to mount it. Once I get that list, I can compare it to the local server list and determine what needs to be uploaded.
Thanks
Dallas
I hate to say it, but if all you’re using the script for is to check to see if files have changed so that you can copy them, you’re re-inventing a wheel that comes with the OS.
OS X (at least recent versions.) comes with rsync, which is designed for mirroring. I suspect that just putting a finely-crafted rsync command into your crontab will do what you need. (As that’s what most UNIX users without the benefit of AppleScript have done for years, anyhow!)
As for curl, it is not recursive (wget is, but I’m not sure it’s any better suited to the task.). You’d have to parse out the directory names and run another instance of curl on them. Provided neither you nor the FTP server are on dial-up, in a cave in the Himalayas, or slow for some other reason, the re-logging in shouldn’t take all that terribly long.
To be fair, I have forgotten what the output of curl looks like for FTP, so I can’t whip something up real quick for you. And my connection’s not being very FTP friendly right now, it seems.
Hi lewellyn,
Thanks for the replies.
Dallas