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
精彩评论