在 Linux 系统中,如果你需要从 FTP 服务器上读取文件,可以使用 ftp 命令行工具,或者使用 wget、curl、scp 等工具。以下是几种常见的方法:
✅ 方法一:使用 ftp 命令行工具
ftp ftp.example.com
然后在 FTP 客户端中执行以下命令:
get filename
这会将 FTP 服务器上的 filename 文件下载到当前目录。
✅ 方法二:使用 wget(推荐)
wget ftp://ftp.example.com/path/to/file
注意:wget 需要安装,可以通过 sudo apt install wget(Debian/Ubuntu)或 sudo yum install wget(CentOS/RHEL)安装。
✅ 方法三:使用 curl(推荐)
curl -O ftp://ftp.example.com/path/to/file
同样需要安装 curl,如 sudo apt install curl(Debian/Ubuntu)或 sudo yum install curl(CentOS/RHEL)。
✅ 方法四:使用 scp(需要 SSH)
scp user@ftp.example.com:/path/to/file /local/path/
需要安装 scp,通常默认已安装。user 是 FTP 服务器上的用户名。
✅ 方法五:使用 ftp + ls + cat(调试用)
ftp ftp.example.com
ls
cat filename
适用于调试 FTP 服务器上的文件是否存在。
✅ 方法六:使用 filezilla 或图形化工具
你可以使用图形化 FTP 客户端(如 FileZilla)来上传或下载文件。
✅ 总结
| 工具 | 优点 | 缺点 |
|---|---|---|
ftp |
简单、直接,支持 FTP 命令 | 需要手动输入密码 |
wget |
简单、跨平台,支持断点续传 | 需要安装 |
curl |
简单、跨平台,支持 HTTP/FTP | 需要安装 |
scp |
无需 FTP,直接传输文件 | 需要 SSH 服务 |
示例:从 FTP 服务器下载文件
wget ftp://ftp.example.com/path/to/file
或
curl -O ftp://ftp.example.com/path/to/file
如需进一步自动化或脚本化操作,可以继续提供需求,我将为你生成对应的 Shell 脚本。


