
-----------------------------------
destroy
Wed Jun 03, 2009 8:26 am

Rebol FTP
-----------------------------------
Hello, I'm new in writing in Rebol and there is one thing I can't handle with. My code is working if I go through the local directories but I can't make it works in FTP directory.
Could you please tell where I'm wrong

REBOL []

my_path: copy system/options/path
files_data: []
feedback_data: []

do-update-files-data: func []                  
[
  change-dir my_path
  if exists? %../ [append files_data %../]
  append files_data sort read my_path
]

update-text-list: func [current_list [object!]]
[
  current_list/sld/data: 0
  current_list/sn: 0
  current_list/sld/redrag
    current_list/lc / max 1 length?
    head current_list/lines
  show current_list
]

do-change-folder: func [selected [file!]]
[
  test_selection: to-file rejoin [my_path selected]
  if dir? test_selection
  [
    my_path: copy test_selection
    lab_path/text: clean-path my_path
    show lab_path
    clear files_data
    do-update-files-data
    update-text-list list_files
  ]
]

do-update-files-data                          

view layout [
  across
  label "Current Folder:"
  lab_path: label to-string my_path 300x50 top
  return
  list_files: text-list data files_data        
    [do-change-folder value]
  btn_quit: button "Quit" [quit]
]

-----------------------------------
btiffin
Wed Jun 03, 2009 9:34 pm

RE:Rebol FTP
-----------------------------------
Hey.  A rebol.  Very cool.

Check out http://www.rebol.org/view-script.r?script=ftpdir.r
and
http://www.rebol.org/cgi-bin/cgiwrap/rebol/documentation.r?script=ftpwrite.r

for some possible hints.

Just as a note, rebols complain quite a bit about the FTP scheme.  It has bugs and even the gurus are not looking forward to being the one tasked with writing the FTP handler for the new REBOL/3.  FTP is an overly detailed and some what ill-specced out internet protocol.

Welcome to REBOL land.  It's handy.

If you want in on the inner discussions, check out http://www.rebol.org/aga-join.r  It has instructions on getting in on the "by invitation only" REBOL communication channel.  Worth the hassle, very helpful bunch, and the "by invite" method keeps the riffraff (usually) out of the very detailed discussions.

Cheers

-----------------------------------
notchent
Sat Aug 29, 2009 10:24 pm

Re: Rebol FTP
-----------------------------------
Hi Destroy :)  I didn't see any of your FTP code, so not sure what you're having trouble with.  You can treat FTP folders much like local file folders, as long as you've got the username and password in the URL path.  You can write and read files/folders, make-dir, use the editor function, change permissions with write/allow, etc.  Maybe this will help:

[code]

REBOL [title: "FTP Tool"]

connect: does [
    either (to-string last p/text) = "/" [
    if error? try [
        f/data: sort append read to-url p/text "../" show f
        ][
        alert "That is not a valid FTP address, or the connection failed."
        ]
    ][
        editor to-url p/text
    ]
]
view center-face layout [
    p: field 600 "ftp://user:pass@website.com/" [connect]
    across
    btn "Connect" [connect]
    btn "Load URL" [
        config: to-file request-file/file %/c/ftp.cfg
        either exists? config [
            if (config  %none) [
                my-urls: copy []
                foreach item read/lines config [append my-urls item]
                if error? try [
                    p/text: copy request-list "Select a URL:" my-urls
                ] [break]
            ]
        ][
            alert "First, save some URLs to that file..."
        ]
        show p focus p
    ]
    btn "Save URL" [
        url: request-text/title/default "URL to save:" p/text
        if url = none [break]
        config-file: to-file request-file/file/save %/c/ftp.cfg
        if (url  none) and (config-file  %none) [
            if not exists? config-file [
                write/lines config-file ftp://user:pass@website.com/
            ]
            write/append/lines config-file to-url url
            alert "Saved"
        ]
    ]
    below
    f: text-list 600x350 [
        either (to-string value) = "../" [
            for i ((length? p/text) - 1) 1 -1 [
                if (to-string (pick p/text i)) = "/" [
                    clear at p/text (i + 1) show p
                    f/data: sort append read to-url p/text "../" show f
                    break
                ]
            ]
        ][
            either (to-string last value) = "/" [
                p/text: rejoin [p/text value] show p
                f/data: sort append read to-url p/text "../" show f
            ][
                if ((request "Edit/view this file?") = true) [
                    either find [%.jpg %.png %.gif %.bmp] suffix? value [
                        view/new layout [
                            image load to-url join p/text value
                        ]
                    ][
                        editor to-url rejoin [p/text value]
                    ]
                ]
            ]
        ]
    ]
    across
    btn "Get Info" [
        p-file: to-url rejoin [p/text f/picked]
        alert rejoin ["Size: " size? p-file " Date: " modified? p-file]
    ]
    btn "Delete" [
        p-file: to-url request-text/title/default "File to delete:"
            join p/text f/picked
        if ((confirm: request "Are you sure?") = true) [delete p-file]
        f/data: sort append read to-url p/text "../" show f
        if confirm = true [alert "File deleted"]
    ]
    btn "Rename" [
        new-name: to-file request-text/title/default "New File Name:"
            to-string f/picked
        if ((confirm: request "Are you sure?") = true) [
            rename (to-url join p/text f/picked) new-name
        ]
        f/data: sort append read to-url p/text "../" show f
        if confirm = true [alert "File renamed"]
    ]
    btn "Copy" [
        new-name: to-url request-text/title/default "New Path:"
            (join p/text f/picked)
        if ((confirm: request "Are you sure?") = true) [
            write/binary new-name read/binary to-url join p/text f/picked
        ]
        f/data: sort append read to-url p/text "../" show f
        if confirm = true [alert "File copied"]
    ]
    btn "New File" [
        p-file: to-url request-text/title/default "New File Name:"
            join p/text "ENTER-A-FILENAME.EXT"
        if ((confirm: request "Are you sure?") = true) [
            write p-file ""
            ; editor p-file
        ]
        f/data: sort append read to-url p/text "../" show f
        if confirm = true [alert "Empty file created - click to edit."]
    ]
    btn "New Dir" [
        make-dir x: to-url request-text/title/default "New folder:" p/text
        alert "Folder created"
        p/text: x show p
        f/data: sort append read to-url p/text "../" show f
    ]
    btn "Download" [
        file: request-text/title/default "File:" (join p/text f/picked)
        l-file: next to-string (find/last (to-string file) "/")
        save-as: request-text/title/default "Save as..." to-string l-file
        write/binary (to-file save-as) (read/binary to-url file)
        alert "Download Complete"
    ]
    btn "Upload" [
        file: to-file request-file
        r-file: request-text/title/default "Save as..." 
            join p/text (to-string to-relative-file file)
        write/binary (to-url r-file) (read/binary file)
        f/data: sort append read to-url p/text "../" show f
        alert "Upload Complete"
    ]
    btn "Chmod" [
        p-file: to-url request-text/default rejoin [p/text f/picked]
        chmod: to-block request-text/title/default "Permissions:"
            "read write execute"
        write/binary/allow p-file (read/binary p-file) chmod
        alert "Permissions changed"
    ]
    do [focus p]
]

[/code]

HTH :) 


ps - You may be interested in having a peek at http://musiclessonz.com/rebol.html
