电子产业一站式赋能平台

PCB联盟网

搜索
查看: 38|回复: 0
收起左侧

Linux命令cURL详解+C语言实现定时上传文件到FTP服务器(送源码)

[复制链接]

473

主题

473

帖子

5188

积分

四级会员

Rank: 4

积分
5188
发表于 2024-7-18 11:50:00 | 显示全部楼层 |阅读模式
点击左上方蓝色“一口Linux”,选择“设为星标
第一时间看干货文章
?【干货】嵌入式驱动工程师学习路线?【干货】Linux嵌入式知识点-思维导图-免费获取?【就业】一个可以写到简历的基于Linux物联网综合项目?【就业】找工作简历模版

kdlmedwku1f6404246111.gif

kdlmedwku1f6404246111.gif


l2tgbzylotx6404246211.jpg

l2tgbzylotx6404246211.jpg

前言前段时间群里讨论,想实现某个文件定时上传到服务器要怎么来实现。我记得之前做过
一个项目:为高通的iot模组编写FOTA功能:实现模组可以远程下载升级镜像包,实现版本升级功能。当时使用的是一个超级强大的工具cURL。心血来潮,决定专门写一篇文章,送给需要的朋友。
文章主要分两部分:
  1.首先介绍cURL的语法;

  2.实现一个定时上传日志文件的一个简单的程序。
概念cURL 是常用的命令行工具,用来请求 Web 服务器。它的名字就是客户端(client)的 URL 工具的意思。
cURL
的原作者是 Daniel Stenberg (目前是 cURL 的核心开发者),同时也是 IETF HTTPbis
工作组的资深成员。Daniel 在 1998 年创建了 curl 项目,他编写了最初的 curl 版本,并创建了 libcurl
库。到目前为止,代码仓库包括的 24000 次 commit 有超过一半是 Daniel 本人提交的,他依然是项目的核心开发者。Daniel
表示已将 curl 视为自己的孩子。

swjpimrfnlx6404246311.jpg

swjpimrfnlx6404246311.jpg

作为一款强力工具,支持的协议包括
(DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS,
POP3, POP3S, RTMP, RTSP, SCP, SFTP, smtP, SMTPS, TELNET and
TFTP),还支持POST、cookies、认证、从指定偏移处下载部分文件等功能,具有用户代理字符串、限速、文件大小、进度条、cookie支持、用户认证、断点续传等特征。
一、命令的安装sudo apt-get install curl
二、cURL命令语法:curl [options] [URL...]
三、URL格式在WWW上,每一信息资源都有统一的且在网上唯一的地址,该地址就叫URL(Uniform Resource Locator,统一资源定位器),它是WWW的统一资源定位标志,就是指网络地址。URL的格式定义要参考 RFC 1808 。
地址:http://www.w3.org/Addressing/rfc1808.txt
《Relative Uniform Resource Locators 》
URL由三部分组成:资源类型、存放资源的主机域名、资源文件名。也可认为由4部分组成:协议、主机、端口、路径URL的一般语法格式为:
protocol :// hostname[:port] / path / [;parameters][?query]#fragment
(带方括号[]的为可选项)。
protocol(协议)指定使用的传输协议,下表列出 protocol 属性的有效方案名称。最常用的是HTTP协议,它也是WWW中应用最广的协议。
  • file 资源是本地计算机上的文件。格式file:///,注意后边应是三个斜杠。
  • ftp 通过 FTP访问资源。格式 FTP://
  • gopher 通过 Gopher 协议访问该资源。
  • http 通过 HTTP 访问该资源。格式 HTTP://
  • https 通过安全的 HTTPS 访问该资源。格式 HTTPS://
  • mailto 资源为电子邮件地址,通过 SMTP 访问。格式 mailto:
  • MMS 通过 支持MMS(流媒体)协议的播放该资源。(代表软件:Windows Media Player)格式 MMS://
  • ed2k 通过 支持ed2k(专用下载链接)协议的P2P软件访问该资源。(代表软件:电驴) 格式 ed2k://
  • Flashget 通过 支持Flashget:(专用下载链接)协议的P2P软件访问该资源。(代表软件:快车) 格式 Flashget://
  • thunder 通过 支持thunder(专用下载链接)协议的P2P软件访问该资源。(代表软件:迅雷) 格式 thunder://
  • news 通过 NNTP 访问该资源。hostname(主机名)是指存放资源的服务器的域名系统(DNS) 主机名或 IP 地址。有时,在主机名前也可以包含连接到服务器所需的用户名和密码(格式:username:password@hostname)。
    port(端口号)整数,可选,省略时使用方案的默认端口,各种传输协议都有默认的端口号,如http的默认端口为80。如果输入时省略,则使用默认端口号。有时候出于安全或其他考虑,可以在服务器上对端口进行重定义,即采用非标准端口号,此时,URL中就不能省略端口号这一项。
    path(路径)由零或多个“/”符号隔开的字符串,一般用来表示主机上的一个目录或文件地址。
    parameters(参数)这是用于指定特殊参数的可选项。
    query(查询)可选,用于给动态网页(如使用CGI、ISAPI、PHP/JSP/ASP/ASP.NET等技术制作的网页)传递参数,可有多个参数,用“&”符号隔开,每个参数的名和值用“=”符号隔开。
    fragment(信息片断)字符串,用于指定网络资源中的片断。例如一个网页中有多个名词解释,可使用fragment直接定位到某一名词解释。
    四、curl命令参数详解:由于linux curl功能十分强大,所以命令参数十分多,下表只筛选出来部分常用的参数,更多参数请运行“man curl”命令查看。
    在以下选项中,(H) 表示仅适用 HTTP/HTTPS ,(F) 表示仅适用于 FTP
    参数1参数2说明

    --anyauth选择 "any" 认证方法 (H)
    -a,--append添加要上传的文件 (F/SFTP)

    --basic使用HTTP基础认证(Basic Authentication)(H)

    --cacert FILECA 证书,用于每次请求认证 (SSL)

    --capath DIRCA 证书目录 (SSL)
    -E,--cert CERT[:PASSWD]客户端证书文件及密码 (SSL)

    --cert-type TYPE证书文件类型 (DER/PEM/ENG) (SSL)

    --ciphers LISTSSL 秘钥 (SSL)

    --compressed请求压缩 (使用 deflate 或 gzip)
    -K,--config FILE指定配置文件

    --connect-timeout SECONDS连接超时设置
    -C,--continue-at OFFSET断点续转
    -b,--cookie STRING/FILECookies字符串或读取Cookies的文件位置 (H)
    -c,--cookie-jar FILE操作结束后,要写入 Cookies 的文件位置 (H)

    --create-dirs创建必要的本地目录层次结构

    --crlf在上传时将 LF 转写为 CRLF

    --crlfile FILE从指定的文件获得PEM格式CRL列表
    -d,--data DATAHTTP POST 数据 (H)

    --data-ascii DATA  ASCII编码 HTTP POST 数据 (H)

    --data-binary DATA  binary编码 HTTP POST 数据 (H)

    --data-urlencode DATA  url编码 HTTP POST 数据 (H)

    --delegation STRING GSS-API委托权限

    --digest使用数字身份验证 (H)

    --disable-eprt禁止使用 EPRT 或 LPRT (F)

    --disable-epsv禁止使用 EPSV (F)
    -D,--dump-header FILE将头信息写入指定的文件

    --egd-file FILE为随机数据设置EGD socket路径(SSL)

    --engine ENGINGE加密引擎 (SSL). "--engine list" 指定列表
    -f,--fail连接失败时不显示HTTP错误信息 (H)
    -F,--form CONTENT模拟 HTTP 表单数据提交(multipart POST) (H)

    --form-string STRING模拟 HTTP 表单数据提交 (H)

    --ftp-account DATA帐户数据提交 (F)

    --ftp-alternative-to-user COMMAND指定替换 "USER [name]" 的字符串 (F)

    --ftp-create-dirs如果不存在则创建远程目录 (F)

    --ftp-method [MULTICWD/NOCWD/SINGLECWD]控制 CWD (F)

    --ftp-pasv使用 PASV/EPSV 替换 PORT (F)
    -P,--ftp-port ADR使用指定 PORT 及地址替换 PASV (F)

    --ftp-skip-pasv-ip跳过 PASV 的IP地址 (F)

    --ftp-pret在 PASV 之前发送 PRET (drftpd) (F)

    --ftp-ssl-ccc在认证之后发送 CCC (F)

    --ftp-ssl-ccc-mode ACTIVE/PASSIVE设置 CCC 模式 (F)

    --ftp-ssl-control ftp登录时需要 SSL/TLS (F)
    -G,--get使用 HTTP GET 方法发送 -d 数据  (H)
    -g,--globoff禁用的 URL 队列 及范围使用 {} 和 []
    -H,--header LINE要发送到服务端的自定义请求头 (H)
    -I,--head仅显示响应文档头
    -h,--help显示帮助
    -0,--http1.0使用 HTTP 1.0 (H)

    --ignore-content-length忽略 HTTP Content-Length 头
    -i,--include在输出中包含协议头 (H/F)
    -k,--insecure允许连接到 SSL 站点,而不使用证书 (H)

    --interface INTERFACE指定网络接口/地址
    -4,--ipv4将域名解析为 IPv4 地址
    -6,--ipv6将域名解析为 IPv6 地址
    -j,--junk-session-cookies读取文件中但忽略会话cookie (H)

    --keepalive-time SECONDSkeepalive 包间隔

    --key KEY私钥文件名 (SSL/SSH)

    --key-type TYPE私钥文件类型 (DER/PEM/ENG) (SSL)

    --krb LEVEL启用指定安全级别的 Kerberos (F)

    --libcurl FILE命令的libcurl等价代码

    --limit-rate RATE限制传输速度
    -l,--list-only只列出FTP目录的名称 (F)

    --local-port RANGE强制使用的本地端口号
    -L,--location跟踪重定向 (H)

    --location-trusted类似  --location 并发送验证信息到其它主机 (H)
    -M,--manual显示全手动

    --mail-from FROM从这个地址发送邮件

    --mail-rcpt TO发送邮件到这个接收人(s)

    --mail-auth AUTH原始电子邮件的起始地址

    --max-filesize BYTES下载的最大文件大小 (H/F)

    --max-redirs NUM最大重定向数 (H)
    -m,--max-time SECONDS允许的最多传输时间

    --metalink处理指定的URL上的XML文件

    --negotiate使用 HTTP Negotiate 认证 (H)
    -n,--netrc必须从 .netrc 文件读取用户名和密码

    --netrc-optional使用 .netrc 或 URL; 将重写 -n 参数

    --netrc-file FILE设置要使用的 netrc 文件名
    -N,--no-buffer禁用输出流的缓存

    --no-keepalive禁用 connection 的 keepalive

    --no-sessionid禁止重复使用 SSL session-ID (SSL)

    --noproxy不使用代理的主机列表

    --ntlm使用 HTTP NTLM 认证 (H)
    -o,--output FILE将输出写入文件,而非 stdout

    --pass PASS传递给私钥的短语 (SSL/SSH)

    --post301在 301 重定向后不要切换为 GET 请求 (H)

    --post302在 302 重定向后不要切换为 GET 请求 (H)

    --post303在 303 重定向后不要切换为 GET 请求 (H)
    -#,--progress-bar以进度条显示传输进度

    --proto PROTOCOLS启用/禁用 指定的协议

    --proto-redir PROTOCOLS在重定向上 启用/禁用 指定的协议
    -x,--proxy [PROTOCOL://]HOST[:PORT]在指定的端口上使用代理

    --proxy-anyauth在代理上使用 "any" 认证方法 (H)

    --proxy-basic在代理上使用 Basic 认证  (H)

    --proxy-digest在代理上使用 Digest 认证 (H)

    --proxy-negotiate在代理上使用 Negotiate 认证 (H)

    --proxy-ntlm在代理上使用 NTLM 认证 (H)
    -U,--proxy-user USER[:PASSWORD]代理用户名及密码

    --proxy1.0 HOST[:PORT]在指定的端口上使用 HTTP/1.0 代理
    -p,--proxytunnel使用HTTP代理 (用于 CONNECT)

    --pubkey KEY公钥文件名 (SSH)
    -Q,--quote CMD在传输开始前向服务器发送命令 (F/SFTP)

    --random-file FILE读取随机数据的文件 (SSL)
    -r,--range RANGE仅检索范围内的字节

    --raw使用原始HTTP传输,而不使用编码 (H)
    -e,--refererReferer URL (H)
    -J,--remote-header-name从远程文件读取头信息 (H)
    -O,--remote-name将输出写入远程文件

    --remote-name-all使用所有URL的远程文件名
    -R,--remote-time将远程文件的时间设置在本地输出上
    -X,--request COMMAND使用指定的请求命令

    --resolve HOST:PORT:ADDRESS将 HOST:PORT 强制解析到 ADDRESS

    --retry NUM出现问题时的重试次数

    --retry-delay SECONDS重试时的延时时长

    --retry-max-time SECONDS仅在指定时间段内重试
    -S,--show-error显示错误. 在选项 -s 中,当 curl 出现错误时将显示
    -s,--silentSilent模式。不输出任务内容

    --socks4 HOST[:PORT]在指定的 host + port 上使用 SOCKS4 代理

    --socks4a HOST[:PORT]在指定的 host + port 上使用 SOCKSa 代理

    --socks5 HOST[:PORT]在指定的 host + port 上使用 SOCKS5 代理

    --socks5-hostname HOST[:PORT] SOCKS5代理,指定用户名、密码

    --socks5-gssapi-service NAME为gssapi使用SOCKS5代理服务名称

    --socks5-gssapi-nec与NEC Socks5服务器兼容
    -Y,--speed-limit RATE在指定限速时间之后停止传输
    -y,--speed-time SECONDS指定时间之后触发限速. 默认 30

    --ssl尝试 SSL/TLS (FTP, IMAP, POP3, SMTP)

    --ssl-reqd需要 SSL/TLS (FTP, IMAP, POP3, SMTP)
    -2,--sslv2使用 SSLv2 (SSL)
    -3,--sslv3使用 SSLv3 (SSL)

    --ssl-allow-beast允许的安全漏洞,提高互操作性(SSL)

    --stderr FILE重定向 stderr 的文件位置. - means stdout

    --tcp-nodelay使用 TCP_NODELAY 选项
    -t,--telnet-option OPT=VAL设置 telnet 选项

    --tftp-blksize VALUE设备 TFTP BLKSIZE 选项 (必须 >512)
    -z,--time-cond TIME基于时间条件的传输
    -1,--tlsv1使用 => TLSv1 (SSL)

    --tlsv1.0使用 TLSv1.0 (SSL)

    --tlsv1.1使用 TLSv1.1 (SSL)

    --tlsv1.2使用 TLSv1.2 (SSL)

    --trace FILE将 debug 信息写入指定的文件

    --trace-ascii FILE类似  --trace 但使用16进度输出

    --trace-time向 trace/verbose 输出添加时间戳

    --tr-encoding请求压缩传输编码 (H)
    -T,--upload-file FILE将文件传输(上传)到指定位置

    --url URL指定所使用的 URL
    -B,--use-ascii使用 ASCII/text 传输
    -u,--user USER[:PASSWORD]指定服务器认证用户名、密码

    --tlsuser USERTLS 用户名

    --tlspassword STRINGTLS 密码

    --tlsauthtype STRINGTLS 认证类型 (默认 SRP)

    --unix-socket FILE通过这个 UNIX socket 域连接
    -A,--user-agent STRING要发送到服务器的 User-Agent (H)
    -v,--verbose显示详细操作信息
    -V,--version显示版本号并退出
    -w,--write-out FORMAT完成后输出什么

    --xattr将元数据存储在扩展文件属性中
    -q
    .curlrc 如果作为第一个参数无效

    五、Linux cURL命令退出码:下面是linux curl命令的错误代码和她们的相应的错误消息,命令执行错误的时候可以通过错误码来查看出错原因,方便开发调试。
    退 出 码错误描述1Unsupported protocol. This build of curl has no support for this protocol.2Failed to initialize.3URL malformed. The syntax was not correct.5Couldn't resolve proxy. The given proxy host could not be resolved.6Couldn't resolve host. The given remote host was not resolved.7Failed to connect to host.8FTP weird server reply. The server sent data curl couldn't parse.9FTP
    access denied. The server denied login or denied access to the
    particular resource or directory you wanted to reach. Most often you
    tried to change to a directory that doesn't exist on the server.11FTP weird PASS reply. Curl couldn't parse the reply sent to the PASS request.13FTP weird PASV reply, Curl couldn't parse the reply sent to the PASV request.14FTP weird 227 format. Curl couldn't parse the 227-line the server sent.15FTP can't get host. Couldn't resolve the host IP we got in the 227-line.17FTP couldn't set binary. Couldn't change transfer method to binary.18Partial file. Only a part of the file was transferred.19FTP couldn't download/access the given file, the RETR (or similar) command failed.21FTP quote error. A quote command returned error from the server.22HTTP
    page not retrieved. The requested url was not found or returned another
    error with the HTTP error code being 400 or above. This return code
    only appears if -f/--fail is used.23Write error. Curl couldn't write data to a local filesystem or similar.25FTP couldn't STOR file. The server denied the STOR operation, used for FTP uploading.26Read error. Various reading problems.27Out of memory. A memory allocation request failed.28Operation timeout. The specified time-out period was reached according to the conditions.30FTP PORT failed. The PORT command failed. Not all FTP servers support the PORT command, try doing a transfer using PASV instead!31FTP couldn't use REST. The REST command failed. This command is used for resumed FTP transfers.33HTTP range error. The range "command" didn't work.34HTTP post error. Internal post-request generation error.35SSL connect error. The SSL handshaking failed.36FTP bad download resume. Couldn't continue an earlier aborted download.37FILE couldn't read file. Failed to open the file. Permissions?38LDAP cannot bind. LDAP bind operation failed.39LDAP search failed.41Function not found. A required LDAP function was not found.42Aborted by callback. An application told curl to abort the operation.43Internal error. A function was called with a bad parameter.45Interface error. A specified outgoing interface could not be used.47Too many redirects. When following redirects, curl hit the maximum amount.48Unknown TELNET option specified.49Malformed telnet option.51The peer's SSL certificate or SSH MD5 fingerprint was not ok.52The server didn't reply anything, which here is considered an error.53SSL crypto engine not found.54Cannot set SSL crypto engine as default.55Failed sending network data.56Failure in receiving network data.58Problem with the local certificate.59Couldn't use specified SSL cipher.60Peer certificate cannot be authenticated with known CA certificates.61Unrecognized transfer encoding.62Invalid LDAP URL.63Maximum file size exceeded.64Requested FTP SSL level failed.65Sending the data requires a rewind that failed.66Failed to initialize SSL Engine.67The user name, password, or similar was not accepted and curl failed to log in.68File not found on TFTP server.69Permission problem on TFTP server.70Out of disk space on TFTP server.71Illegal TFTP operation.72Unknown TFTP transfer ID.73File already exists (TFTP).74No such user (TFTP).75Character conversion failed.76Character conversion functions required.77Problem with reading the SSL CA cert (path? access rights?).78The resource referenced in the URL does not exist.79An unspecified error occurred during the SSH session.80Failed to shut down the SSL connection.82Could not load CRL file, missing or wrong format (added in 7.19.0).83Issuer check failed (added in 7.19.0).XXMore error codes will appear here in future releases. The existing ones are meant to never change.六、用法演示:为节省篇幅,部分操作不再贴上执行结果。
    1、查看网页源码直接在curl命令后加上网址,就可以看到网页源码。我们以网址www.sina.com为例(选择该网址,主要因为它的网页代码较短):
    root@ubuntu:/home/peng# curl www.sohu.com
    307 Temporary Redirect
    "white">
    307 Temporary Redirect
    nginx

    执行结果显示 307 Temporary Redirect,说明该网址需要重定向。
    如果要把这个网页保存下来,可以使用-o参数,这就相当于使用wget命令了。
    curl -o [文件名] www.sohu.com
    2、自动跳转有的网址是自动跳转的。使用-L参数,curl就会跳转到新的网址。
    curl -L www.sohu.com
    键入上面的命令,结果就自动跳转为www.sohu.com.cn。
    3、显示头信息-i参数可以显示http response的头信息,连同网页代码一起。
    root@ubuntu:/home/peng/driver/test#  curl -i www.sohu.com
    HTTP/1.1 307 Temporary Redirect
    Content-Type: text/html
    Content-Length: 180
    Connection: keep-alive
    Server: nginx
    Date: Tue, 25 Aug 2020 10:10:54 GMT
    Location: https://www.sohu.com/
    FSS-Cache: from 9790436.18244590.10468709
    FSS-Proxy: Powered by 2384755.3433341.3062915

    307 Temporary Redirect
    "white">
    307 Temporary Redirect
    nginx


    -I参数则是只显示http response的头信息。
    4、显示通信过程-v参数可以显示一次http通信的整个过程,包括端口连接和http request头信息。
    root@ubuntu:/home/peng/driver/test#  curl -v www.sohu.com
    * About to connect() to www.sohu.com port 80 (#0)
    *   Trying 240e:83:201:3700::5... connected
    > GET / HTTP/1.1
    > User-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
    > Host: www.sohu.com
    > Accept: */*
    >
    307 Temporary Redirect
    "white">
    307 Temporary Redirect
    nginx

    * Connection #0 to host www.sohu.com left intact
    * Closing connection #0
    如果你觉得上面的信息还不够,那么下面的命令可以查看更详细的通信过程。
    curl --trace output.txt www.sohu.com
    或者
    curl --trace-ascii output.txt www.sohu.com
    运行后,请打开output.txt文件查看。
    5、发送表单信息发送表单信息有GET和POST两种方法。GET方法相对简单,只要把数据附在网址后面就行。
    curl example.com/form.cgi?data=xxx
    POST方法必须把数据和网址分开,curl就要用到--data参数。
    curl -X POST --data "data=xxx" example.com/form.cgi
    如果你的数据没有经过表单编码,还可以让curl为你编码,参数是--data-urlencode。
    curl -X POST--data-urlencode "date=April 1" example.com/form.cgi
    6、HTTP动词curl默认的HTTP动词是GET,使用-X参数可以支持其他动词。
    curl -X POST www.example.com
    curl -X DELETE www.example.com
    7、文件上传假定文件上传的表单是下面这样:
    "POST" enctype='multipart/form-data' action="upload.cgi">
    type=file name=upload>
    type=submit name=press value="OK">
    你可以用curl这样上传文件:
    curl --form upload=@localfilename --form press=OK [URL]
    8、Referer字段有时你需要在http request头信息中,提供一个referer字段,表示你是从哪里跳转过来的。
    curl --referer http://www.example.com http://www.example.com
    9、User Agent字段这个字段是用来表示客户端的设备信息。服务器有时会根据这个字段,针对不同设备,返回不同格式的网页,比如手机版和桌面版。
    iPhone4的User Agent是
    Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7
    curl可以这样模拟:
    curl --user-agent "[User Agent]" [URL]
    10、cookie使用--cookie参数,可以让curl发送cookie。
    curl --cookie "name=xxx" www.example.com
    至于具体的cookie的值,可以从http response头信息的Set-Cookie字段中得到。
    -c cookie-file可以保存服务器返回的cookie到文件,-b cookie-file可以使用这个文件作为cookie信息,进行后续的请求。
    curl -c cookies http://example.com
    curl -b cookies http://example.com
    11、增加头信息有时需要在http request之中,自行增加一个头信息。--header参数就可以起到这个作用。
    $ curl --header "Content-Type:application/json" http://example.com
    12、认证使用curl选项 -u 可以完成HTTP或者FTP的认证,可以指定密码,也可以不指定密码在后续操作中输入密码:
    curl -u user:pwd http://man.linuxde.net
    curl -u user http://man.linuxde.net
    13、FTP1)、列出ftp服务器上的目录列表curl ftp://www.xxx.com/ --user name:passwd
    curl ftp://www.xxx.com/ –u name:passwd #简洁写法
    curl ftp://name:passwd@www.xxx.com #简洁写法2

    例如:在IP地址192.168.43.117上搭建FTP服务器,并设置用户名为user,密码为123456。
    现在我们要显示服务器上根目录下的所有文件信息,命令如下:
    curl -u user:123456 ftp://192.168.43.117
    执行结果如下:

    wx0upydbuq36404246411.png

    wx0upydbuq36404246411.png

    简洁写法:
    curl ftp://user:123456@192.168.43.117
    执行结果如下:

    13c4cenikya6404246511.png

    13c4cenikya6404246511.png

    2)、只列出目录,不显示进度条curl ftp://www.xxx.com –u name:passwd -s
    3)、下载一个文件:命令如下:

    curl ftp://www.xxx.com/size.zip –u name:passwd -o size.zip
    示例如下:从服务器的根目录下下载文件test.c,保存到本地,本地文件名也为test.c。【注意】如果没有-o选项,程序会吧数据流定向到stdout,即直接把文件内容显示到终端上。
    curl ftp://user:123456@192.168.43.117/test.c -o test.c
    执行结果如下:

    iabm0uo5y3h6404246611.png

    iabm0uo5y3h6404246611.png

    简洁模式
    curl -u user:123456 ftp://192.168.43.117/list.h -o list.h
    执行结果如下:

    2osmezy3tjd6404246711.png

    2osmezy3tjd6404246711.png

    4)、上载一个文件:curl –u name:passwd -T size.mp3 ftp://www.xxx.com/mp3/
    举例如下:
    curl -u user:123456 ftp://192.168.43.117/ -T list.h

    z5bzdqec0cx6404246811.png

    z5bzdqec0cx6404246811.png

    可以看到文件并没有上传成功,返回错误码是25,参考第五章
    25 FTP couldn't STOR file. The server denied the STOR operation, used for FTP uploading.
    可知,是因为服务器没有赋予存储的权限,所以设置服务器的write权限即可。
  • 回复

    使用道具 举报

    发表回复

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则


    联系客服 关注微信 下载APP 返回顶部 返回列表