Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re[2]: interactive FTP

From: fantam:mailandnews at: 24-Jun-2001 16:02

Excellent. Thanks again, AR. I noticed that Jeff's post on schemes has made it to an article on www.rebolforces.com. I wrote a couple of functions that are meant to be used in conjunction with your scheme (mftp). exists: func [port [port!] file [file! string!] /local content] [ insert port "LIST" content: copy port content: parse/all content "^/" foreach line content [ if (last parse line "") = to-string file [return true] ] return false ] isdir: func [port [port!] file [file! string!] /local content] [ insert port "LIST" content: copy port content: parse/all content "^/" foreach line content [ if find/case line file [ if (first line) = #"d" [return true] ] ] return false ] ftp-bin-upload: func [port [port!] file [file!] /local data] [ data: read/binary file insert port "TYPE I" print copy port insert port reform ["STOR" file] insert port data print copy port ] makedir: func [port [port!] file [file! string!]] [ insert port reform ["MKD" file] print copy port ] The next one is a more sophisticated exists function, that can accept a url, like ftp://ftp.ftp.com/test/test/test.txt and it will navigate to the needed directory, and tell you if the file exists. If you give a url like ftp://ftp.ftp.com/test/test/, it should work as well, and tell you whether the directory path exists or not. exists: func [port [port!] file [file! string! url!] /local content current-exists path] [ current-exists: func [file] [ insert port "LIST" content: copy port content: parse/all content "^/" foreach line content [ if (last parse line "") = to-string file [return true] ] return false ] cdup: does [ insert port "CWD /" copy port ] either url? file [ url-obj: make object! [user: pass: host: port-id: path: target: none] net-utils/url-parser/parse-url url-obj file path: parse url-obj/path "/" foreach item path [ if (current-exists port item) [ insert port reform ["CWD" item] if find/any copy/part copy port 3 "5??" [cdup return false] ] ] either not none? url-obj/target [current-exists url-obj/target] [cdup return true] ] [current-exists file] ] Comments are welcome. I'll probably write more functions like the above. If anyone's interested, let me know. that's it for now. fantam