View script | License | Download documentation as: HTML or editable | Download script | History |
[0.062] 22.894k
Documentation for: ftpwrite.rUsage document for the FTP examples.This documents ALL the simple FTP examples.1. Introduction to FTP handlingThere is a full suite of scripts that demonstrate how easy it is to use FTP in REBOL. 2. Similar configuration for all ftp examplesThere 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
3. Using %ftpallto.rChange 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 learnLoading %./ 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.rA 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 learnREBOL 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.rYou 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 learnREBOLs powerful url! datatype allows for all kind of operations that most programming languages require many lines of code to accomplish. 6. Using %ftpdel.rDon'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 learnWith great power, comes great responsibility. 7. Using %ftpdircheck.rAnother 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 learnQuery commands work over FTP. 8. Using %ftpdir.rYou 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 learnYou 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.rNow this is cool. After changing the specifications, you can execute REBOL code directly out of an FTP server. 9.1. What you can learnREBOL is pretty cool. It's too bad the world had to lock down the internet. Very few open FTP servers anymore. 10. Using %ftpdownbin.rREBOL supports binary FTP transfers. 10.1. What you can learn.REBOL supports binary FTP tranfers. 11. Using %ftpdownload.rThis 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 learnREBOL 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. 12. Using %ftpdown.rThis 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 learnNote 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.rThis is very similar to %ftpdownload.r, but uses a different pattern and doesn't prompt for each matching filename. 13.1. What you can learnThe same lessons as learned in %ftpdownload.r. 14. Using %ftpinfo.rThis program demonstrates that you can request file size and modification timestamps over FTP. 14.1. What you can learnMany operations that work on local files will also work with FTP or other url! data. 15. Using %ftpmakedir.rYou can create directories over FTP. 15.1. What you can learnREBOL uses make-dir to mkdir. 16. Using %ftpread.rA simple display of a file read over FTP 16.1. What you can learnREBOL is great at keeping simple things simple. 17. Using %ftprename.rYou can rename files over FTP. 17.1. What you can learnREBOL 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.rSimilar to %ftpdown.r, this script will send the listed files up to an FTP server. 18.1. What you can learnThe same lessons as mentioned in %ftpdown.r 19. Using %ftpup.rA binary upload to an FTP server. 19.1. What you can learnREBOL can send binary data to an FTP filename. 20. Using %ftpwrite.rThis script writes a string to a text file on an FTP server. 20.1. What yo can learnFTP operations don't alway use file!, or url! information. You can send data into an FTP spec. 21. What you can learn overallThese scripts cover most of the FTP operations supported by REBOL. 22. Credits
|