Documention for: ftpwrite.r Created by: btiffin on: 29-Apr-2007 Last updated by: btiffin on: 6-May-2007 Format: text/editable Downloaded on: 24-Apr-2024 [h1 Usage document for the FTP examples. [h1 This documents ALL the simple FTP examples. [contents [numbering-on [h2 Introduction to FTP handling [p There is a full suite of scripts that demonstrate how easy it is to use FTP in REBOL. [h2 Similar configuration for all ftp examples [p 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. [list [li The FTP server address [li The username [li The password [li Filename to operate on, or list of filenames to operate on. list] [p Details for each example follow. With the following assumptions [list [li GNU/Linux [li Running an FTP daemon on your localhost [li user account "user" [li password "pass" [li Home directory /home/user/ with an examples/ subdirectory that is safe for you to play in, including potentially destroying. list] [h2 Using %ftpallto.r [p Change ftp-to: line to [asis ftp-to: user:password@localhost/examples asis] [p Assumptions aside, in real life use your username, your password, the FTP site domain name and destination directory specification. [p Now running %ftpallto.r will transfer all %.r files in the same directory as the %ftpallto.r script to /home/user/examples/ [h3 What you can learn [p 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. [p 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. [p 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. [h2 Using %ftpappend.r [p A nice, one-liner. Change the username, password, FTP domain, and file REBOL will hide all the details of the file append. [h3 What you can learn [p 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. [h2 Using %ftpcheck.r [p 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. [h3 What you can learn [p REBOLs powerful url! datatype allows for all kind of operations that most programming languages require many lines of code to accomplish. [h2 Using %ftpdel.r [p 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!. [h3 What you can learn [p With great power, comes great responsibility. [h2 Using %ftpdircheck.r [p 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. [h3 What you can learn [p Query commands work over FTP. [h2 Using %ftpdir.r [p You can read complete directories using FTP, and REBOL will package up the **file!** specs in a nice tidy **block!**. [p None of the FTP sites listed in this scripts will have open permissions, so you will have to change the specifications. [h3 What you can learn [p You can read complete directories using FTP and REBOL will package up the filenames in a nice tidy block. [p If you don't have proper permissions, a script will abort. [h2 Using %ftpdo.r [p Now this is cool. After changing the specifications, you can execute REBOL code directly out of an FTP server. [h3 What you can learn [p REBOL is pretty cool. It's too bad the world had to lock down the internet. Very few open FTP servers anymore. [h2 Using %ftpdownbin.r [p REBOL supports binary FTP transfers. [h3 What you can learn. [p REBOL supports binary FTP tranfers. [h2 Using %ftpdownload.r [p 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. [h3 What you can learn [p REBOL does support wildcards, sorta. The expression [asis find/match/any file pattern asis] uses the **/any** refinement to allow * and ? mark wildcards, similar to DOS. Similar, but not the same. It's worth further experimenting. [h2 Using %ftpdown.r [p 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. [h3 What you can learn [p 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. [h2 Using %ftphtml.r [p This is very similar to %ftpdownload.r, but uses a different **pattern** and doesn't prompt for each matching filename. [h3 What you can learn [p The same lessons as learned in %ftpdownload.r. [h2 Using %ftpinfo.r [p This program demonstrates that you can request file size and modification timestamps over FTP. [h3 What you can learn [p Many operations that work on local files will also work with FTP or other **url!** data. [h2 Using %ftpmakedir.r [p You can create directories over FTP. [h3 What you can learn [p REBOL uses **make-dir** to **mkdir**. [h2 Using %ftpread.r [p A simple display of a file read over FTP [h3 What you can learn [p REBOL is great at keeping simple things simple. [h2 Using %ftprename.r [p You can rename files over FTP. [h3 What you can learn [p 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. [h2 Using %ftpupload.r [p Similar to %ftpdown.r, this script will send the listed files up to an FTP server. [h3 What you can learn [p The same lessons as mentioned in %ftpdown.r [h2 Using %ftpup.r [p A binary upload to an FTP server. [h3 What you can learn [p REBOL can send binary data to an FTP filename. [h2 Using %ftpwrite.r [p This script writes a string to a text file on an FTP server. [h3 What yo can learn [p FTP operations don't alway use file!, or url! information. You can send data into an FTP spec. [h2 What you can learn overall [p These scripts cover most of the FTP operations supported by REBOL. [h2 Credits [table/att/border="1px" [row [cell %ftpallto.r [cell Original author: Unknown [row [cell %ftpappend.r [cell Original author: Unknown [row [cell %ftpcheck.r [cell Original author: Unknown [row [cell %ftpdel.r [cell Original author: Unknown [row [cell %ftpdircheck.r [cell Original author: Unknown [row [cell %ftpdir.r [cell Original author: Unknown [row [cell %ftpdo.r [cell Original author: Unknown [row [cell %ftpdownbin.r [cell Original author: Unknown [row [cell %ftpdownload.r [cell Original author: Unknown [row [cell %ftpdown.r [cell Original author: Unknown [row [cell %ftphtml.r [cell Original author: Unknown [row [cell %ftpinfo.r [cell Original author: Unknown [row [cell %ftpmakedir.r [cell Original author: Unknown [row [cell %ftpread.r [cell Original author: Unknown [row [cell %ftprename.r [cell Original author: Unknown [row [cell %ftpup.r [cell Original author: Unknown [row [cell %ftpupload.r [cell Original author: Unknown [row [cell %ftpwrite.r [cell Original author: Unknown table] Most of the above Unkown author credits are probably Carl Sassenrath. [list [li The rebol.org Library Team [li Usage document by Brian Tiffin, Library Team Apprentice, [date list]