【问题标题】:How to upload an image to FTP using FTPClient?如何使用 FTPClient 将图像上传到 FTP?
【发布时间】:2011-10-12 13:28:09
【问题描述】:

我正在使用

FTPClient con = new FTPClient();
try
{
    con.connect(HOST);
    if (con.login (LOGIN, PASSWORD))
    {
        con.enterLocalPassiveMode(); 
        InputStream instream = context.openFileInput(filename);
        con.storeFile(filename, instream);
        instream.close();
    }
}
catch (Exception e)
{
    e.printStackTrace();
}
try
{
    con.logout();
    con.disconnect();
}

使用文本文件即可。有了图片文件,图片就很诡异了:

image

如何纠正?

【问题讨论】:

  • 您使用的是哪个 ftp 库?尝试以二进制模式传输图像。

标签: android image ftp


【解决方案1】:

尝试更改文件类型:

con.setFileType(FTP.BINARY_FILE_TYPE)

http://commons.apache.org/net/apidocs/org/apache/commons/net/ftp/FTPClient.html#setFileType%28int%29

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-05
    • 2014-12-07
    • 1970-01-01
    • 1970-01-01
    • 2018-09-27
    • 1970-01-01
    • 1970-01-01
    • 2017-07-26
    相关资源
    最近更新 更多