+ Reply to Thread
Results 1 to 2 of 2

Thread: Upload a file to server using FTP

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    36

    Upload a file to server using FTP

    I don`t know how to use FTP in android using java , i want to upload a file to my FTP Server.
    Can you help me with that please ?

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    36
    Here is how you can upload files to your FTP Server
    Code:
    	// import the library
        import org.apache.commons.net.ftp.FTPClient;
    
    	// make an object
        FTPClient fClient = new FTPClient();
    
        fClient.connect(InetAddress.getByName("SERVER ADDRESS"));
        fClient.login("USERNAME", "PASSWORD");
        fClient.changeWorkingDirectory("PATH TO WORKING DIRECTORY");
    
        if (fClient.getReplyString().contains("250")) {
            fClient.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
            BufferedInputStream buffIn = null;
            buffIn = new BufferedInputStream(new FileInputStream("FULL_PATH_TO_LOCAL_FILE"));
            fClient.enterLocalPassiveMode();
            ProgressInputStream progressInput = new ProgressInputStream(buffIn, progressHandler);
    		
            boolean result = fClient.storeFile(localAsset.getFileName(), progressInput);
            buffIn.close();
            fClient.logout();
            fClient.disconnect();
    	}

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts