Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

vindarel
vindarel

Posted on

     

FTP and SFTP clients for Common Lisp

You thought all companies would provide well-documented web APIs today? Well, some use a blank .docx and (S)FTP.

For Common Lisp,cl-ftp is one of those libraries that look unmaintained and undocumented, but it works very well, and it is short enough to quickly grab how to use it. It's quite well thought-out, even. It is a pure Lisp library, no system dependencies required.

For example you can do this to send a file:

(ftp:with-ftp-connection(conn:hostnamehostname:username(find-ftp-username):passwordpassword:passive-ftp-pt)(ftp:store-fileconnlocal-filenamefilename))
Enter fullscreen modeExit fullscreen mode

You'll have to look at this for more commands:https://github.com/pinterface/cl-ftp/blob/master/simple-client.lisp

we haveftp-shell,ftp-put,ftp-list,ftp-get,ftp-pwd, and etc for ls, help, cd, dir.

ForSFTP, we must find another means. I didn't find a pure CL library, and it is annoyingly not straightforward to run a SFTP command with a password on the command line.Some solutions exist and I choselftp. It is included in Debian.

We can run:

lftp sftp://user:password@host  -e "put local-file.name; bye"
Enter fullscreen modeExit fullscreen mode

or better, with the password in an environment variable:

export LFTP_PASSWORD="just_an_example"lftp --env-password sftp://user@host  -e "put local-file.name; bye"
Enter fullscreen modeExit fullscreen mode

In my scripts I need to handle a connection profile, and even several ones for development, so I ended up with code that I replicate from project to project, hence a new utility:

https://github.com/vindarel/lftp-wrapper

Now do:

CL-USER>(use-package:lftp-wrapper);; optional, or:CL-USER>(uiop:add-package-local-nickname:lftp:lftp-wrapper)CL-USER>(defvarprofile(make-profile-from-plist(uiop:read-file-form"CREDS.lisp-expr"))#<PROFILEprotocol:"sftp",login:"user",port:10022,server:"prod.com",password?T>CL-USER>(defvarcommand(put:cd"I/":local-filename"data.csv"))#<PUTcd:"I/",filename:"data.csv"{1007153883}>CL-USER>(runprofilecommand)success!
Enter fullscreen modeExit fullscreen mode

We created a profile from credentials on file and from environment variables, we created a command object, and we executed the command for the profile.

We could wrap many more features from lftp. But I follow needs-driven development. So far, it works and it sends my files.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Full-stack, Python, Common Lisp in production.Building a video course to learn Lisp efficiently.
  • Location
    France
  • Joined

More fromvindarel

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp