开发者

How to upload an image to FTP using FTPClient?

I'm using

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.printStackTra开发者_StackOverflow社区ce();
}
try
{
    con.logout();
    con.disconnect();
}

With a textfile it works. With an image file, the image is very weird :

image

How to correct it?


try changing the fileType :

con.setFileType(FTP.BINARY_FILE_TYPE)

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜