Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private class FTPUploader extends AsyncTask<URL, Integer, Long> {
- protected Long doInBackground(URL... urls) {
- String data = "/pathimage/filename.jpg";
- File sourceFile = new File(data);
- FTPClient con = new FTPClient();
- try {
- con.connect("ftp.ftpServer.it", 21);
- if (con.login("user", "password")) {
- con.setFileType(FTP.BINARY_FILE_TYPE);
- con.enterLocalPassiveMode();
- if (sourceFile.exists()) {
- InputStream input = new FileInputStream(sourceFile);
- boolean result = con.storeFile("/folder/newfilename.jpg", input);
- input.close();
- if (result) {
- System.out.println(result);
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- try {
- if (sourceFile.exists()) {
- con.logout();
- con.disconnect();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }
- }
Add Comment
Please, Sign In to add comment