- package com.photo;
-
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.InputStream;
-
- import org.apache.commons.net.ftp.FTPClient;
- import org.apache.commons.net.ftp.FTPReply;
-
- public class FileTool {
-
-
- public static boolean uploadFile(String url, int port, String username,
- String password, String path, String filename, InputStream input) {
- boolean success = false;
- FTPClient ftp = new FTPClient();
-
-
- try {
- int reply;
- ftp.connect(url, port);
-
- ftp.login(username, password);
- reply = ftp.getReplyCode();
- if (!FTPReply.isPositiveCompletion(reply)) {
- ftp.disconnect();
- return success;
- }
- ftp.changeWorkingDirectory(path);
- ftp.storeFile(filename, input);
-
- input.close();
- ftp.logout(); //否则服务器上无法显示图片
- success = true;
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (ftp.isConnected()) {
- try {
- ftp.disconnect();
- } catch (IOException ioe) {
- }
- }
- }
- return success;
- }
-
-
- public static void main(String[] args) {
-
- FileInputStream in = null ;
- File dir = new File("G://pathnew");
- File files[] = dir.listFiles();
- if(dir.isDirectory()) {
- for(int i=0;i<files.length;i++) {
- try {
- in = new FileInputStream(files[i]);
- boolean flag = uploadFile("17.8.119.77", 21, "android", "android",
- "/photo/", "412424123412341234_20130715120334_" + i + ".jpg", in);
- System.out.println(flag);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- }
-
- }
- }
http://blog.csdn.net/liuzhidong123/article/details/9341269
android传送照片到FTP服务器,布布扣,bubuko.com
android传送照片到FTP服务器
原文:http://www.cnblogs.com/daishuguang/p/3883900.html