There is a full suite of scripts that demonstrate how easy it is to use FTP in REBOL.
There are three things that need to be changed, for local use, in all FTP examples. And a fourth for examples that need filenames, or a directory to scan to find filenames.
Details for each example follow. With the following assumptions
Change ftp-to: line to
ftp-to: user:password@localhost/examples
Assumptions aside, in real life use your username, your password, the FTP site domain name and destination directory specification.
Now running %ftpallto.r will transfer all %.r files in the same directory as the %ftpallto.r script to /home/user/examples/
Loading %./ returns a list of files from the current directory. REBOL has a file! datatype. These filenames are not strings! but actual file! specs. It is the reason for the % character. The lexical scanner uses this percent to inform REBOL that the symbol is a filename, or file! data. It might take a little while to get used to, but then eventually you feel the power.
Note the write ftp-to/:file. REBOL will intelligently build filenames out of parts, and return a file! or in this case a url! datatype.
Also note in that same sequence the :file. get-words in REBOL allow for variable substition in places that most computer languages would not easily allow.
A nice, one-liner. Change the username, password, FTP domain, and file REBOL will hide all the details of the file append.
REBOL can accomplish a lot in one-line. REBOL does a lot in the background. Before it appends data to the file, it knows to tell FTP to change to the correct directory.
You can actually run this one without modification, but it'll cost resources on ftp.rebol.com and it won't actually work. You don't have permission. Even though it will be a quick port connect and disconnect, good REBOL programmers know not to use up these valuable resources while experimenting or learning.
REBOLs powerful url! datatype allows for all kind of operations that most programming languages require many lines of code to accomplish.
Don't. No, just kidding. This example shows that you can remove files and directories from the destination FTP server. Remember the warning at the top about destroying your local examples/ directory? This type of script is a perfect way of doing so. REBOL will delete files or directories with the DELETE native and an FTP url!.
With great power, comes great responsibility.
Another script whose time has passed. Public access to ftp.rebol.com is no longer supported. You need to change the url! specification to something you have permission to use. So back to ftp://user:pass@localhost/examples and this script will display It's a directory, but probably not in bold.
Query commands work over FTP.
You can read complete directories using FTP, and REBOL will package up the file! specs in a nice tidy block!.
None of the FTP sites listed in this scripts will have open permissions, so you will have to change the specifications.
You can read complete directories using FTP and REBOL will package up the filenames in a nice tidy block.
If you don't have proper permissions, a script will abort.
Now this is cool. After changing the specifications, you can execute REBOL code directly out of an FTP server.
REBOL is pretty cool. It's too bad the world had to lock down the internet. Very few open FTP servers anymore.
REBOL supports binary FTP transfers.
REBOL supports binary FTP tranfers.
This script is an example of how to download all %.gz files from a site. Change the FTP specs, change the pattern and you will download files matching the pattern. Well actually the script will prompt for and only transfer files on a keyboard y response.
REBOL does support wildcards, sorta. The expression
find/match/any file patternuses the /any refinement to allow * and ? mark wildcards, similar to DOS. Similar, but not the same. It's worth further experimenting.
This scripts show off how you can make up block! lists of file names for FTP download. This is something that come in handy during development. You'll have to change all the FTP specifications, and use your own filenames in the files block.
Note the entities in the files block are not named with % (but they could be) and REBOL will still know to build a url! datatype.
This is very similar to %ftpdownload.r, but uses a different pattern and doesn't prompt for each matching filename.
The same lessons as learned in %ftpdownload.r.
This program demonstrates that you can request file size and modification timestamps over FTP.
Many operations that work on local files will also work with FTP or other url! data.
You can create directories over FTP.
REBOL uses make-dir to mkdir.
A simple display of a file read over FTP
REBOL is great at keeping simple things simple.
You can rename files over FTP.
REBOL can only rename within a single directory. You can't use the REBOL rename native to move files across directory structures. That is promised to be changed in REBOL versions beyond 2.7.
Similar to %ftpdown.r, this script will send the listed files up to an FTP server.
The same lessons as mentioned in %ftpdown.r
A binary upload to an FTP server.
REBOL can send binary data to an FTP filename.
This script writes a string to a text file on an FTP server.
FTP operations don't alway use file!, or url! information. You can send data into an FTP spec.
These scripts cover most of the FTP operations supported by REBOL.
%ftpallto.r | Original author: Unknown |
%ftpappend.r | Original author: Unknown |
%ftpcheck.r | Original author: Unknown |
%ftpdel.r | Original author: Unknown |
%ftpdircheck.r | Original author: Unknown |
%ftpdir.r | Original author: Unknown |
%ftpdo.r | Original author: Unknown |
%ftpdownbin.r | Original author: Unknown |
%ftpdownload.r | Original author: Unknown |
%ftpdown.r | Original author: Unknown |
%ftphtml.r | Original author: Unknown |
%ftpinfo.r | Original author: Unknown |
%ftpmakedir.r | Original author: Unknown |
%ftpread.r | Original author: Unknown |
%ftprename.r | Original author: Unknown |
%ftpup.r | Original author: Unknown |
%ftpupload.r | Original author: Unknown |
%ftpwrite.r | Original author: Unknown |