Script Library: 1240 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Documentation for: ftpwrite.r


Usage document for the FTP examples.

This documents ALL the simple FTP examples.

1. Introduction to FTP handling

There is a full suite of scripts that demonstrate how easy it is to use FTP in REBOL.

2. Similar configuration for all ftp examples

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.

  • The FTP server address
  • The username
  • The password
  • Filename to operate on, or list of filenames to operate on.

Details for each example follow. With the following assumptions

  • GNU/Linux
  • Running an FTP daemon on your localhost
  • user account user
  • password pass
  • Home directory /home/user/ with an examples/ subdirectory that is safe for you to play in, including potentially destroying.

3. Using %ftpallto.r

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/

3.1. What you can learn

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.

4. Using %ftpappend.r

A nice, one-liner. Change the username, password, FTP domain, and file REBOL will hide all the details of the file append.

4.1. What you can learn

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.

5. Using %ftpcheck.r

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.

5.1. What you can learn

REBOLs powerful url! datatype allows for all kind of operations that most programming languages require many lines of code to accomplish.

6. Using %ftpdel.r

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!.

6.1. What you can learn

With great power, comes great responsibility.

7. Using %ftpdircheck.r

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.

7.1. What you can learn

Query commands work over FTP.

8. Using %ftpdir.r

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.

8.1. What you can learn

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.

9. Using %ftpdo.r

Now this is cool. After changing the specifications, you can execute REBOL code directly out of an FTP server.

9.1. What you can learn

REBOL is pretty cool. It's too bad the world had to lock down the internet. Very few open FTP servers anymore.

10. Using %ftpdownbin.r

REBOL supports binary FTP transfers.

10.1. What you can learn.

REBOL supports binary FTP tranfers.

11. Using %ftpdownload.r

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.

11.1. What you can learn

REBOL does support wildcards, sorta. The expression

find/match/any file pattern 
uses the /any refinement to allow * and ? mark wildcards, similar to DOS. Similar, but not the same. It's worth further experimenting.

12. Using %ftpdown.r

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.

12.1. What you can learn

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.

13. Using %ftphtml.r

This is very similar to %ftpdownload.r, but uses a different pattern and doesn't prompt for each matching filename.

13.1. What you can learn

The same lessons as learned in %ftpdownload.r.

14. Using %ftpinfo.r

This program demonstrates that you can request file size and modification timestamps over FTP.

14.1. What you can learn

Many operations that work on local files will also work with FTP or other url! data.

15. Using %ftpmakedir.r

You can create directories over FTP.

15.1. What you can learn

REBOL uses make-dir to mkdir.

16. Using %ftpread.r

A simple display of a file read over FTP

16.1. What you can learn

REBOL is great at keeping simple things simple.

17. Using %ftprename.r

You can rename files over FTP.

17.1. What you can learn

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.

18. Using %ftpupload.r

Similar to %ftpdown.r, this script will send the listed files up to an FTP server.

18.1. What you can learn

The same lessons as mentioned in %ftpdown.r

19. Using %ftpup.r

A binary upload to an FTP server.

19.1. What you can learn

REBOL can send binary data to an FTP filename.

20. Using %ftpwrite.r

This script writes a string to a text file on an FTP server.

20.1. What yo can learn

FTP operations don't alway use file!, or url! information. You can send data into an FTP spec.

21. What you can learn overall

These scripts cover most of the FTP operations supported by REBOL.

22. Credits

%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
Most of the above Unkown author credits are probably Carl Sassenrath.
  • The rebol.org Library Team
  • Usage document by Brian Tiffin, Library Team Apprentice, Last updated: 6-May-2007