ftp module
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
ftp module
I've put a version of an alternative ftp module up at
http://unbalanced-parentheses.nfshost.c ... ds/ftp.lsp
Is it good enough yet to go into the http://newlisp.nfshost.com/modules/?
Tim's added some cool stuff...
http://unbalanced-parentheses.nfshost.c ... ds/ftp.lsp
Is it good enough yet to go into the http://newlisp.nfshost.com/modules/?
Tim's added some cool stuff...
The code is nice, very readable, and easy to understand. But perhaps we need more documentation explaining the usage of FTP:config and explaining the possibility of either doing the file transfer in just one function call or with several function calles explicitly connecting etc., showing which functions are used and in what sequence etc, with a simple example.
Perhaps Tim can test it too, so we have at least tried it on two different servers?
Perhaps Tim can test it too, so we have at least tried it on two different servers?
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
-
- Posts: 253
- Joined: Thu Oct 07, 2004 7:21 pm
- Location: Palmer Alaska USA
I've written an application that will make use of mftp and I plan to test
it against one other server tomorrow - at least and maybe more, given
time.
I'm still getting my "feet wet" with newlispdoc and still learning Lutz's
documentation protocol, but here is a rough draft of documentation,
let me know what you all think.
<grin>I'd hate to make more work for Lutz, but I think it would be great
if there was a doc protocol for variables, but maybe there is....
Tim
it against one other server tomorrow - at least and maybe more, given
time.
I'm still getting my "feet wet" with newlispdoc and still learning Lutz's
documentation protocol, but here is a rough draft of documentation,
let me know what you all think.
Code: Select all
;; @syntax (FTP:config ...<quoted-var1> <val1> <quoted-var1> <val2> ...)
;; @description Sets control variables. Throws error if var isn't "registered" in 'control-vars
;; @example
;; (FTP:config 'quiet 1 'report-file "Uploading: ") => changes FTP:quiet and FTP:report-file
;; control variables are as follows:
;; quiet: Set to nil to report command transfers
;; report: set to non-nil to report and track data transfers
;; intro: Simple header, displayed if 'report is true
;; report-file: Precedes announcement of file name when 'report'ing
;; packet-marker: One or more characters to print to stdout when a packet is sent
;; NOTE: the intent of config is to
;; 1) Simplify code
;; 2) Prevent typos
;; 3) Create some sort of boundary between "private" and "public" variables
if there was a doc protocol for variables, but maybe there is....
Tim
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Nice work guys..!
A question..
Why does get-file return 'nil after succes?
I would expect 'true on success and 'nil perhpas "nothing more to fetch?
but could be a matter of taste perhpas? ;-)
...............................................................................................................................................................................................................................................................................................................nil
A question..
Why does get-file return 'nil after succes?
I would expect 'true on success and 'nil perhpas "nothing more to fetch?
but could be a matter of taste perhpas? ;-)
...............................................................................................................................................................................................................................................................................................................nil
-- (define? (Cornflakes))
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
-
- Posts: 253
- Joined: Thu Oct 07, 2004 7:21 pm
- Location: Palmer Alaska USA
I ran into a problem. For some reason, 'send-files - being called from
'upload with a list of files as in
was getting a string instead of list and therefore 'map complained.
So I added a coercion so that send-files looks like so:
I suspect that this was a result of the way that I composed the parameter
list to FTP:upload - which looks like this:
Where 'ftp-info is a list containing connection data and (upload-info 0)
is member 0 of a nested list - itself a list of filenames for upload.
Anyway, although I've got a ways to go before getting the hang of
newlisp, I can verify another server connection with a multiple upload.
Would welcome comments on whether the coercion should remain or
a better way to compose the arguments.
cheers
tim
'upload with a list of files as in
Code: Select all
(map send-files (args))
So I added a coercion so that send-files looks like so:
Code: Select all
(define (send-files f-list)
(if (not(list? f-list))(set 'f-list(list f-list))) ;; make sure f-list _is_ a list
(map send-file f-list)
(report "Sent " (length f-list) " files"))
list to FTP:upload - which looks like this:
Code: Select all
(set 'res(apply mftp:upload (append ftp-info (upload-info 0))))
is member 0 of a nested list - itself a list of filenames for upload.
Anyway, although I've got a ways to go before getting the hang of
newlisp, I can verify another server connection with a multiple upload.
Would welcome comments on whether the coercion should remain or
a better way to compose the arguments.
cheers
tim
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
This works for me, as long as the files are supplied in a list. Perhaps you could set a temp variable to the list and print it first, to see what you're actually passing to apply...(set 'res(apply mftp:upload (append ftp-info (upload-info 0))))
I can't get get-file to work properly now... It returns nil too often...
Edit: I think I know what I did. I managed to revert to an old version of get-file without realising. Ha... I'm glad that I don't do this for a living - I would have just got fired... :)
-
- Posts: 253
- Joined: Thu Oct 07, 2004 7:21 pm
- Location: Palmer Alaska USA
:-) Actually, I added a 'test variable - implementation is meant to be
temporary - so
mftp:upload looks like this:
Note to window users - there's a number of utilities in linux that
have a "test" switch that allows the user to test functionality before
commitment.. I'm kind of emulating that protocol.
temporary - so
mftp:upload looks like this:
Code: Select all
(define (upload host user-name password working-dir)
(cond (test
(println "host = " host)
(println "user-name = " user-name)
(println "password = " password)
(println "working-dir = " working-dir)
(println "args = " (args))
)
((not test)
(and
(connect host)
(login user-name password working-dir)
(report intro)
(map send-files (args))
(logout)
(disconnect))
))
)
;; call to FTP:config
(mftp:config 'test true)
;; and output looks like this:
host = 000.000.000.000
user-name = <user>
password = <pwd>
working-dir = /cgi-bin/libraries/python
args = ("mylib.py" "valid.py")
have a "test" switch that allows the user to test functionality before
commitment.. I'm kind of emulating that protocol.
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
That's the sort of thing. Your formulation works as you hoped:
The files are transferred OK, but res will (always) be nil! That's because either logout or disconnect returns nil at some point, and upload does them after the transfers. I'll have to put the tracer on it later.
By the way, I noticed that you do this:
where report was originally a boolean flag, and gets redefined as a function. But doesn't that mean that report is always true?
Code: Select all
(set 'list1 '("ftp..." "user" "pass" "tmp"))
(set 'list2 '(("test1.txt" "test2.txt")))
(append list1 list2)
(set 'res (apply upload (append list1 list2)))
...
Connected to host. Upload follows:
227 Entering Passive Mode (...).
150 Opening BINARY mode data connection for test1.txt
Sending: test1.txt.
226 Transfer complete
227 Entering Passive Mode (...).
150 Opening BINARY mode data connection for test2.txt
Sending: test2.txt.
226 Transfer complete
Sent 2 files221 Goodbye.
By the way, I noticed that you do this:
Code: Select all
(define (report) ; print progress etc.
(if report (doargs (i) (print i))))
-
- Posts: 253
- Joined: Thu Oct 07, 2004 7:21 pm
- Location: Palmer Alaska USA
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
I've put in some more fixes and uploaded it again. Version 0.12... :)
Perhaps we should host this somewhere like http://github.com/ so everyone could have a go...!
Perhaps we should host this somewhere like http://github.com/ so everyone could have a go...!
-
- Posts: 253
- Joined: Thu Oct 07, 2004 7:21 pm
- Location: Palmer Alaska USA
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
I updated this for newLISP v10 - it didn't seem to work with recent updates for some reason... It's on http://unbalanced-parentheses.nfshost.c ... index.html.
Lutz - you have a link on your modules page which could be updated one day.
Lutz - you have a link on your modules page which could be updated one day.
Thanks for making your modules 10.0 ready. The link on:
http://www.newlisp.org/modules/
has been corrected
http://www.newlisp.org/modules/
has been corrected