List Ipfs Directory Using Curl (Not Direct Ipfs Commands)
Fleetinglist ipfs directory using cur
#!/bin/bash
API_URL="http://localhost:5001"
DIRCID=$1
list_files_only() {
local cid="$1"
local path="$2"
curl -X POST -s "$API_URL/api/v0/ls?arg=$cid" | jq -c '.Objects[0].Links[]' | while read -r link; do
name=$(echo "$link" | jq -r '.Name')
hash=$(echo "$link" | jq -r '.Hash')
type=$(echo "$link" | jq -r '.Type')
full_path="$path/$name"
if [ "$type" = "2" ]; then # File
echo "$DIRCID$full_path"
elif [ "$type" = "1" ]; then # Directory
list_files_only "$hash" "$full_path"
fi
done
}
if [ -z "$DIRCID" ]; then
echo "Usage: $0 <directory CID>"
exit 1
fi
list_files_only "$DIRCID" ""