invenia / FTPClient.jl

Julia FTP client using LibCURL.jl
Mozilla Public License 2.0
22 stars 4 forks source link
ftp ftp-client julia

FTPClient.jl

CI codecov

A Julia FTP client using LibCURL supporting FTP and FTP over SSL.

Examples

Depending on the settings of the FTP server you are connecting to you may need to deal with various security settings.

Once you've created your FTP instance you can use many of the filesystem functions that Julia provides. A quick example showing some of the functions available:

julia> cd(ftp, "Documents/School")

julia> pwd(ftp)
"/Documents/School"

julia> readdir(ftp)
1-element Array{String,1}:
 "Assignment1.txt"
 "Assignment2.txt"

julia> io = download(ftp, "Assignment1.txt");  # Download as IO stream

julia> download(ftp, "Assignment2.txt", "./A2/Assignment2.txt");  # Save file to a specified path

julia> upload(ftp, "Assignment3.txt", ".")  # Upload local file "Assignment3.txt" to FTP server home directory

julia> open("Assignment3.txt") do fp
           upload(ftp, fp, "Assignment3-copy.txt")  # Upload IO content as file "Assignment3-copy.txt" on FTP server
       end

julia> mv(ftp, "Assignment3-copy.txt", "Assignment3-dup.txt")

julia> rm(ftp, "Assignment3-dup.txt")

julia> mkdir(ftp, "tmp")

julia> rmdir(ftp, "tmp")

julia> close(ftp)

If you want to upload a file but retry on failures you can do the following:

julia> ftp_retry = retry(delays=fill(5.0, 3)) do
           upload(ftp, "Assignment3.txt", ".")
       end

julia> ftp_retry()

FAQ

Downloaded files are unusable

Try downloading file in both binary and ASCII mode to see if one of the files is usable.

Linux and Travis CI

Travis CI currently [does not reliably support FTP connections on sudo-enabled Linux]https://blog.travis-ci.com/2018-07-23-the-tale-of-ftp-at-travis-ci). This will usually manifest itself as a Connection Timeout error. Disable sudo for a workaround.