Ftp put 破坏了我的 gif ?

Mat*_*ler 2 ftp

使用以下脚本,我在我的 ftp 服务器上上传 gif。脚本似乎有效,但是当我尝试在浏览器中访问图像时,它们坏了。知道为什么吗?

#!/bin/sh                                   
HOST='myftp'                       
USER='mylogin'                              

ftp -n $HOST <<END_SCRIPT                   
quote USER $USER                            
quote PASS $1                               
put $2                                      
quit                                        
END_SCRIPT                                  
exit 0     
Run Code Online (Sandbox Code Playgroud)

Den*_*nis 12

您的图像以网络 ASCII 模式而非二进制模式上传。

传输文本文件(纯文本、HTML 等)时,网络 ASCII 模式很有用。例如,如果您将文本文件从运行 Windows 的客户端传输到运行 Linux 的服务器,它会自动将所有 Windows 换行符 ( 13 10) 转换为 Unix 换行符 ( 10) 并添加文件结尾字符 ( 10)。

显然,这会在传输二进制文件(如图像)时导致文件损坏。

要切换到二进制模式,请在执行此命令之前put

binary
Run Code Online (Sandbox Code Playgroud)

来自man ftp

ascii    Set the file transfer type to network ASCII.
         This is the default type.

binary   Set the file transfer type to support binary image transfer.
Run Code Online (Sandbox Code Playgroud)