cargo install duf
```
+### With docker
+
+```
+docker run -v /tmp:/tmp -p 5000:5000 --rm -it docker.io/sigoden/duf /tmp
+```
+
### Binaries on macOS, Linux, Windows
Download from [Github Releases](https://github.com/sigoden/duf/releases), unzip and add duf to your $PATH.
--allow-delete Allow delete files/folders
--allow-symlink Allow symlink to files/folders outside root directory
--allow-upload Allow upload files/folders
- -b, --bind <address> Specify bind address [default: 127.0.0.1]
+ -b, --bind <address> Specify bind address [default: 0.0.0.0]
--cors Enable CORS, sets `Access-Control-Allow-Origin: *`
-h, --help Print help information
-p, --port <port> Specify port to listen on [default: 5000]
duf folder_name
```
-Listen on all Interfaces and port 3000
-
-```
-duf -b 0.0.0.0 -p 3000
-```
-
Allow all operations such as upload, delete
```sh
duf --allow-all
-# or
-duf -A
```
Only allow upload operation
duf --render-spa
```
-Serve https
+Use https
```
duf --tls-cert my.crt --tls-key my.key
Arg::new("address")
.short('b')
.long("bind")
- .default_value("127.0.0.1")
+ .default_value("0.0.0.0")
.help("Specify bind address")
.value_name("address"),
)
fn parse_path<P: AsRef<Path>>(path: P) -> BoxResult<PathBuf> {
let path = path.as_ref();
if !path.exists() {
- bail!("error: path \"{}\" doesn't exist", path.display());
+ return Err(format!("Path `{}` doesn't exist", path.display()).into());
}
env::current_dir()
p.push(path); // If path is absolute, it replaces the current path.
std::fs::canonicalize(p)
})
- .or_else(|err| {
- bail!(
- "error: failed to access path \"{}\": {}",
- path.display(),
- err,
- )
- })
+ .map_err(|err| format!("Failed to access path `{}`: {}", path.display(), err,).into())
}
/// Construct socket address from arguments.
pub fn address(&self) -> BoxResult<SocketAddr> {
format!("{}:{}", self.address, self.port)
.parse()
- .or_else(|err| {
- bail!(
- "error: invalid address {}:{} : {}",
- self.address,
- self.port,
- err,
- )
- })
+ .map_err(|_| format!("Invalid bind address `{}:{}`", self.address, self.port).into())
}
}
-macro_rules! bail {
- ($($tt:tt)*) => {
- return Err(From::from(format!($($tt)*)))
- }
-}
-
mod args;
mod server;
}
fn handle_err<T>(err: Box<dyn std::error::Error>) -> T {
- eprintln!("Server error: {}", err);
+ eprintln!("error: {}", err);
std::process::exit(1);
}