如何在Linux中使用ffsend从命令行安全地共享文件

时间:2020-03-21 11:44:56  来源:igfitidea点击:

感谢Mozilla的基金会,我们提供了一个免费的在线文件共享服务Firefox Send,该服务使我们能够通过Internet端到端加密轻松,安全地共享文件。

尽管通过Web浏览器与Firefox发送服务共享文件非常容易,但是对于那些喜欢CLI而不是GUI的人来说,还有一个非官方的命令行客户端。
认识ffsend,这是用于Firefox Send的功能齐全的CLI客户端,可以从Linux上的命令行安全地共享文件。

使用ffsend客户端,我们可以直接从终端向Firefox发送/从Firefox上传/下载文件和目录。
此外,还可以检查或者删除共享文件,查看共享文件信息,查看文件历史记录,上传之前的存档文件,更改共享文件的密码,并且还会有更多功能! Ffsend具有内置的共享URL缩短器和QR代码生成器,当前支持Firefox Send v3和v2.
ffsend是免费的开放源代码,是用Rust编程语言编写的。

在Linux上安装ffsend

在Linux机器上安装ffsend之前,请确保已安装以下准备工作:

  • OpenSSL和CA证书,
  • xclip或者xsel用于剪贴板复制。

大多数Linux发行版的默认存储库中都提供了它们。
例如,我们可以使用以下命令将它们安装在Debian,Ubuntu和其他基于DEB的系统上:

$sudo apt install openssl ca-certificates xclip xsel

安装必要的依赖项后,请从发行版页面下载最新的ffsend版本。

在撰写本教程时,最新版本为0.2.58.

$wget https://github.com/timvisee/ffsend/releases/download/v0.2.58/ffsend-v0.2.58-linux-x64-static

将其移到$PATH中:

$sudo mv ffsend-* /usr/local/bin/ffsend

最后,使其可执行:

$sudo chmod +x /usr/local/bin/ffsend

这是安装最新的ffsend版本的官方推荐方法。

如果我们使用的是Arch Linux,请使用任何AUR帮助器(例如Yay)从AUR安装ffsend。

$yay -S ffsend-bin

还有另一种安装ffsend的方法。
但是,我们可能会得到一些过时的版本。

使用捕捉:

$snap install ffsend

使用NIX包管理器:

$nix-channel --update
$nix-env --install ffsend

Fedora :

$sudo dnf install ffsend

对于其他安装方法,请检查最后链接的GitHub官方页面。

使用ffsend从命令行安全地共享文件

在不带任何参数的情况下运行ffsend时,我们会看到一个基本的帮助部分。

$ffsend 
ffsend 0.2.58
Usage: ffsend [FLAGS] <SUBCOMMAND> ...
Easily and securely share files from the command line.
A fully featured Firefox Send client.
Missing subcommand. Here are the most used:
    ffsend upload <FILE> ...
    ffsend download <URL> ...
To show all subcommands, features and other help:
    ffsend help [SUBCOMMAND]

让我为我们展示一些实际的例子。

基本用法

要将文件快速上传到Firefox发送服务而没有任何安全性,请执行以下操作:

$ffsend upload video.mp4

输出示例:

Upload complete 
https://send.firefox.com/download/c1be7dd726089352/#BHZUSp2LY-Aaamv3k0UOmw

现在,我们可以通过任何媒介(邮件或者短信)将此URL共享给任何人。
收件人可以从其Web浏览器或者使用ffsend客户端下载共享文件。

可以使用ffsend命令下载文件:

$ffsend download https://send.firefox.com/download/c1be7dd726089352/#BHZUSp2LY-Aaamv3k0UOmw

如我们所见,在上传文件时,我们没有包含任何安全控制。
因此,拥有此URL的任何人都可以下载数据。
让我们看一些带有安全选项的高级命令。

进阶用法

以下命令将上传受密码保护的给定文件:

如我们所见,我已将文件video.mp4的密码设置为123456.
这只是出于学习目的。
使用任何强密码,而不只是123456.

现在,收件人必须在下载文件时输入密码。

$ffsend download https://send.firefox.com/download/ea100bcc75145f9d/#JZMkNn4ypj7HesEnayUo7A
Password: 
Download complete

同样,我们可以设置其他安全控件,例如,

  • 选择文件链接何时到期(即在下载次数或者天数之后)。
  • 上传时存档文件。

看下面的例子:

$ffsend upload video.mp4 --archive --downloads 1 --expiry-time 5m --password 123456

上面的命令将;

  • 上传之前先存档输入文件,
  • 指定下载限制为1,
  • 指定5分钟的上传到期时间,
  • 并将密码设置为123456.

下载时,将询问收件人是否要提取存档文件。

$ffsend download https://send.firefox.com/download/6306f2fe3cfe7e09/#E2tuLr2aZGCg3avQkFj3Ew
Password: 
You're downloading an archive, extract it into the selected directory? [Y/n]: y
Download complete Extracting...

如果他们选择不提取,则将获得tar文件。
然后,我们可以使用任何其他合适的实用程序来手动提取它。

将可共享链接复制到剪贴板

要在上传后将文件链接复制到剪贴板,请运行:

$ffsend upload --copy video.mp4

请注意,我们必须已安装xclip或者xsel才能启用此功能。

打开可共享的浏览器链接

如果要在上传后自动打开默认Web浏览器的共享链接,请运行:

$ffsend upload --open video.mp4 
Upload complete https://send.firefox.com/download/dd2127439ef80320/#GdBgW8DZy9jwvqsp0dCnVA

检查远程文件的详细信息

要检查远程文件的详细信息,请运行:

$ffsend info https://send.firefox.com/download/dd2127439ef80320/#GdBgW8DZy9jwvqsp0dCnVA

输出示例为:

ID: dd2127439ef80320 
Downloads: 0 of 1 
Expiry: 23h56m (86188s)

检查是否存在远程文件

要验证是否存在远程文件,请运行:

$ffsend exists https://send.firefox.com/download/dd2127439ef80320/#GdBgW8DZy9jwvqsp0dCnVA

查看上传历史记录

当我们想知道已上传了多少文件以及文件何时到期时,这可能会有所帮助。

$ffsend history

输出示例:

#  LINK                                                                        EXPIRE  
1  https://send.firefox.com/download/96a12b3d8884819d/#Vn5LRU_PgRKIAsHFoud0-g  ~23h51m  
2  https://send.firefox.com/download/ea100bcc75145f9d/#JZMkNn4ypj7HesEnayUo7A  ~23h21m  
3  https://send.firefox.com/download/75027ad5870be002/#JvfR57OHaJ1I6LHPM2tFgQ  ~23h19m  
4  https://send.firefox.com/download/c1be7dd726089352/#BHZUSp2LY-Aaamv3k0UOmw  ~22h11m

删除远程文件

可以如下所示删除远程文件。

$ffsend delete https://send.firefox.com/download/dd2127439ef80320/#GdBgW8DZy9jwvqsp0dCnVA

ffsend别名

ffsend为所有子命令提供别名。
例如,我们可以仅对“上载”子命令使用“ u”或者“ up”。

例如,可以使用以下任一命令上传文件:

$ffsend upload video.mp4

或者,

$ffsend u video.mp4

或者,

$ffsend up video.mp4

这是一些别名。

  • u或者up-上传文件
  • d或者下-下载文件
  • del或者rm-删除文件
  • p-设置密码
  • e-检查是否存在远程文件
  • i-获取有关远程文件的信息

获得帮助

要查看可用标志,选项和子命令的列表以及说明,请参阅帮助部分:

$ffsend --help
ffsend 0.2.58
Tim Visee <Hyman@theitroad>
Easily and securely share files from the command line.
A fully featured Firefox Send client.
USAGE:
    ffsend [FLAGS] [OPTIONS] [SUBCOMMAND]
FLAGS:
    -f, --force          
            Force the action, ignore warnings
    -h, --help           
            Prints help information
    -i, --incognito      
            Don't update local history for actions
    -I, --no-interact    
            Not interactive, do not prompt
    -q, --quiet          
            Produce output suitable for logging and automation
    -V, --version        
            Prints version information
    -v, --verbose        
            Enable verbose information and logging
    -y, --yes            
            Assume yes for prompts

OPTIONS:
    -A, --api <VERSION>                 
            Server API version to use, one of:
            2, 3: Firefox Send API versions
            auto, -: probe server to determine [env: FFSEND_API]
        --basic-auth <USER:PASSWORD>    
            HTTP basic authentication credentials [env: FFSEND_BASIC_AUTH]
    -H, --history <FILE>                
            Use the specified history file [env: FFSEND_HISTORY]
    -t, --timeout <SECONDS>             
            Request timeout (0 to disable) [env: FFSEND_TIMEOUT]
    -T, --transfer-timeout <SECONDS>    
            Transfer timeout (0 to disable) [env: FFSEND_TRANSFER_TIMEOUT]

SUBCOMMANDS:
    upload        Upload files [aliases: u, up]
    download      Download files [aliases: d, down]
    debug         View debug information [aliases: dbg]
    delete        Delete a shared file [aliases: del, rm]
    exists        Check whether a remote file exists [aliases: e]
    generate      Generate assets [aliases: gen]
    help          Prints this message or the help of the given subcommand(s)
    history       View file history [aliases: h]
    info          Fetch info about a shared file [aliases: i]
    parameters    Change parameters of a shared file [aliases: params]
    password      Change the password of a shared file [aliases: pass, p]
    version       Determine the Send server version [aliases: v]
The public Send service that is used as default host is provided by Mozilla.
This application is not affiliated with Mozilla, Firefox or Firefox Send.