You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, as I needed some more info that just item names from the readdir directlry, I have implemented the following customisations to (a) allow the listing of any directory (not just the current one) and (b) the reporting of the details of each element and not just the name.
This is not breaking because by default the function returns the same output as the current version of readdir.
This should answer also similar needs, like the request by @omus in #82 .
Let me know if you would be interested, I'll clean it up a bit, make a docstring and create a pull request if it is the case...
The function:
# Modified to get the info if it is a directory and to list info on any directories, not only current onefunctionFTP_readdir(ftp::FTP,dir=pwd(ftp);details=false)
resp =nothingtry
resp = FTPClient.ftp_command(ftp.ctxt, "LIST $dir")
catch err
ifisa(err, FTPClient.FTPClientError)
err.msg ="Failed to list directories."endrethrow()
end
dir =split(read(resp.body, String), '\n')
dir =filter(x ->!isempty(x), dir)
if(details)
entries = NamedTuple{(:type, :permissions, :n, :user, :group, :size, :date, :name), Tuple{Char, SubString{String}, SubString{String}, SubString{String}, SubString{String}, SubString{String}, SubString{String}, String}}[]
for item in dir
details =split(item)
details_nt = (type=details[1][1],permissions=details[1][2:end],n=details[2],user=details[3],group=details[4],size=details[5],date=join(details[6:8], ''),name=join(details[9:end], ''))
push!(entries,details_nt)
endreturn entries
else
names = [join(split(line)[9:end], '') for line in dir]
return names
endend
An example:
julia> ftp =FTP(hostname ="palantir.boku.ac.at", username ="anonymous", password ="")
URL: ftp://anonymous@palantir.boku.ac.at/
Transfer: passive mode
Security: none
julia>FTP_readdir(ftp,"Public/ImprovedForestCharacteristics")
11-element Vector{String}:"Age""Alive_Tree_Carbon""Basal_Area""Biomass""Diameter""Height""Readme.txt""Stand_Density_Index""Stem_Number""Tree_Species_Group""Volume"
julia>FTP_readdir(ftp,"Public/ImprovedForestCharacteristics",details=true)
11-element Vector{NamedTuple{(:type, :permissions, :n, :user, :group, :size, :date, :name), Tuple{Char, SubString{String}, SubString{String}, SubString{String}, SubString{String}, SubString{String}, SubString{String}, String}}}:
(type ='d', permissions ="rwxrwx---", n ="2", user ="1000", group ="100", size ="4096", date ="Jan 25 2022", name ="Age")
(type ='d', permissions ="rwxrwx---", n ="2", user ="1000", group ="100", size ="4096", date ="Jan 25 2022", name ="Alive_Tree_Carbon")
(type ='d', permissions ="rwxrwx---", n ="2", user ="1000", group ="100", size ="4096", date ="Jan 25 2022", name ="Basal_Area")
(type ='d', permissions ="rwxrwx---", n ="2", user ="1000", group ="100", size ="4096", date ="Jan 25 2022", name ="Biomass")
(type ='d', permissions ="rwxrwx---", n ="2", user ="1000", group ="100", size ="4096", date ="Jan 25 2022", name ="Diameter")
(type ='d', permissions ="rwxrwx---", n ="2", user ="1000", group ="100", size ="4096", date ="Jan 25 2022", name ="Height")
(type ='-', permissions ="rwxrwx---", n ="1", user ="1000", group ="100", size ="2103", date ="Jan 24 2022", name ="Readme.txt")
(type ='d', permissions ="rwxrwx---", n ="2", user ="1000", group ="100", size ="4096", date ="Jan 25 2022", name ="Stand_Density_Index")
(type ='d', permissions ="rwxrwx---", n ="2", user ="1000", group ="100", size ="4096", date ="Jan 25 2022", name ="Stem_Number")
(type ='d', permissions ="rwxrwx---", n ="3", user ="1000", group ="100", size ="4096", date ="Jun 20 2022", name ="Tree_Species_Group")
(type ='d', permissions ="rwxrwx---", n ="2", user ="1000", group ="100", size ="4096", date ="Jan 25 2022", name ="Volume")
The text was updated successfully, but these errors were encountered:
sylvaticus
changed the title
Implemented proposal: improvements to readdir (any dir, oprional details)
Implemented proposal: improvements to readdir (any dir, optional details)
Jul 13, 2023
Hello, as I needed some more info that just item names from the
readdir
directlry, I have implemented the following customisations to (a) allow the listing of any directory (not just the current one) and (b) the reporting of the details of each element and not just the name.This is not breaking because by default the function returns the same output as the current version of
readdir
.This should answer also similar needs, like the request by @omus in #82 .
Let me know if you would be interested, I'll clean it up a bit, make a docstring and create a pull request if it is the case...
The function:
An example:
The text was updated successfully, but these errors were encountered: