Sample code for 30+ languages & platforms
Java

Upload Multiple Files Matching Pattern

See more FTP Examples

The MPutFiles method can be called to upload all files matching a wildcarded filename pattern from a local filesystem directory.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Ftp2;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Ftp2 ftp = new Ftp2();

        ftp.setHostname("ftp.example.com");
        ftp.setUsername("my_login");
        ftp.setPassword("my_password");

        // Connect and login to the FTP server.
        try {
            ftp.connect();

            // Change to the remote directory where the files will be uploaded.
            // for the FTP account.
            ftp.changeRemoteDir("junk");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // Upload all files with filenames matching "c:/temp/ftp_*.asp"
        int numFilesUploaded = ftp.mPutFiles("c:/temp/ftp_*.asp");
        if (numFilesUploaded < 0) {
            System.out.println(ftp.getLastErrorText());
            return;
        }

        ftp.disconnect();

        System.out.println(numFilesUploaded + " Files Uploaded!");
    }
}