当前位置 : 主页 > 手机开发 > android >

android – 如何使用FTPClient将图像上传到FTP?

来源:互联网 收集:自由互联 发布时间:2021-06-11
我正在使用 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.clos
我正在使用

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

怎么纠正呢?

尝试更改fileType:

con.setFileType(FTP.BINARY_FILE_TYPE)

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

网友评论