IT袋

当前位置:主页 > 经验教程 > 建站编程 >

curl命令怎么用

curl命令怎么用 curl常用命令及参数详解(4)

更新:2023-08-11 17:28:08 来源:IT袋 作者:马勇
导读:curl命令怎么用,用curl进行认证 使用curl选项 -u 可以完成HTTP或者FTP的认证,可以指定密码,也可以不指定密码在后续操作中输入密码: curl -u user:pwd https://www.itmemo.cn/ curl

curl命令怎么用

用curl进行认证

使用curl选项 -u 可以完成HTTP或者FTP的认证,可以指定密码,也可以不指定密码在后续操作中输入密码:

curl -u user:pwd https://www.itmemo.cn/
curl -u user https://www.itmemo.cn/

只打印响应头部信息

通过-I或者-head可以只打印出HTTP头部信息:

curl -I https://www.itmemo.cn/

HTTP/1.1 200 OK
Server: nginx
Date: Tue, 09 Aug 2022 02:59:38 GMT
Content-Type: text/html
Content-Length: 62774
Last-Modified: Tue, 09 Aug 2022 02:01:21 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "62f1bff1-f536"
Accept-Ranges: bytes

以下是官方翻译过来的cURL简易教程

从网络服务器获取主页:

curl https://www.itmemo.cn/

在 funet 的 ftp-server 上获取用户主目录的 README 文件:

curl ftp://ftp.funet.fi/README

使用端口 8000 从服务器获取网页:

curl http://www.weirdserver.com:8000/

获取 FTP 站点的目录列表:

curl ftp://ftp.funet.fi

从字典中获取 curl 的定义:

curl dict://dict.org/m:curl

一次获取两个文档:

curl ftp://ftp.funet.fi/ http://www.weirdserver.com:8000/

从 FTPS 服务器获取文件:

curl ftps://files.are.secure.com/secrets.txt

或者使用更合适的 FTPS 方式来获取相同的文件:

curl --ftp-ssl ftp://files.are.secure.com/secrets.txt

使用 SFTP 从 SSH 服务器获取文件:

curl -u username sftp://example.com/etc/issue

使用 SCP 使用私钥(不受密码保护)从 SSH 服务器获取文件以进行身份​​验证:

curl -u username: --key ~/.ssh/id_rsa scp://example.com/~/file.txt

使用 SCP 使用私钥(受密码保护)从 SSH 服务器获取文件以进行身份​​验证:

curl -u username: --key ~/.ssh/id_rsa --pass private_key_password
scp://example.com/~/file.txt

从 IPv6 Web 服务器获取主页:

curl "http://[2001:1890:1112:1::20]/"

从 SMB 服务器获取文件:

curl -u "domain\username:passwd" smb://server.example.com/share/file.txt

下载到文件

获取网页并存储在具有特定名称的本地文件中:

curl -o thatpage.html http://www.example.com/

获取网页并存储在本地文件中,使本地文件获取远程文档的名称(如果URL中没有指定文件名部分,则会失败):

curl -O http://www.example.com/index.html

获取两个文件并使用它们的远程名称存储它们:

curl -O www.haxx.se/index.html -O curl.se/download.html

使用密码

FTP

要使用名称+密码 ftp 文件,请将它们包含在 URL 中,例如:

curl ftp://name:passwd@machine.domain:port/full/path/to/file

或使用 -u 标志指定它们,例如

curl -u name:passwd ftp://machine.domain:port/full/path/to/file

相关阅读