Curl 从其他URL上载文件时保留内容类型,而不在本地保存

Curl 从其他URL上载文件时保留内容类型,而不在本地保存,curl,wget,Curl,Wget,考虑到许多文件(或一个大文件),我想从一台服务器下载并上传到另一台服务器,而无需在本地存储文件。现在,我正在使用: wget-q-O-| curl--silent--show error--fail-X PUT-d@ 但这会上载默认内容类型为application/x-www-form-urlencoded的文件。有没有办法保留原始内容类型?使用curl只需设置标题,例如,-H'Content-Type:text/html': cat 1.html | curl --silent --show-

考虑到许多文件(或一个大文件),我想从一台服务器下载并上传到另一台服务器,而无需在本地存储文件。现在,我正在使用:

wget-q-O-| curl--silent--show error--fail-X PUT-d@


但这会上载默认
内容类型为application/x-www-form-urlencoded
的文件。有没有办法保留原始内容类型?

使用curl只需设置标题,例如,
-H'Content-Type:text/html'

cat 1.html | curl --silent --show-error --fail -X PUT -H 'Content-Type: text/html' -d @- localhost:8000
在服务器上,您可以获得:

Content-Type: text/html
通常(与浏览器一样),文件上载需要一个方法=post和enctype=“multipart/form data”。然后可以为每个零件设置内容类型。使用curl时,您可以使用:

curl ... -F "file=@-;type=text/html" <destination>
您需要从wget标题中提取相关的内容类型。也许可以使用--save headers选项?首先将内容读入变量
文件
,将标题字段值提取到变量
content\u type
,然后将除标题以外的所有内容传递给curl,您现在可以使用上面的$content\u type调用它:

wget ... | { file=$(</dev/stdin); content_type=$(echo "$file" | sed -n '1,/^\r$/ { /^Content-Type: /{ s/.*: \(.*\)/\1/p; q } }'); echo "$file" | sed '1,/^\r$/d' | curl ... }
wget…|{文件=$(
wget ... | { file=$(</dev/stdin); content_type=$(echo "$file" | sed -n '1,/^\r$/ { /^Content-Type: /{ s/.*: \(.*\)/\1/p; q } }'); echo "$file" | sed '1,/^\r$/d' | curl ... }