APACHE COMMONS / NOTES</>↗Apache Commons19 Jul 2008
This example demonstrates how to delete file from FTP server. package org.kodejava.commons.net; import org.apache.commons.net.ftp.FTPClient; import java.io.IOException; public class FTPDeleteDemo { public static void main(String[] args) { FTPClient client = new FTPClient(); try { client.connect("ftp.example.com"); client.login("demo", "password"); // Delete file on the FTP server. When the FTP delete // process completes, it returns true. String filename […]
APACHE COMMONS / NOTES</>↗Apache Commons18 Jul 2008
This example demonstrates how to retrieve a list of files from FTP server. First we create an instance of org.apache.commons.net.ftp.FTPClient. Connect to the FTP server and login with your username and password. The listFiles() method of the FTPClient return the list of filenames contained in the current working directory. null if the list could not […]
APACHE COMMONS / NOTES</>↗Apache Commons14 Jul 2008
This example demonstrates how to upload file to FTP server. package org.kodejava.commons.net; import org.apache.commons.net.ftp.FTPClient; import java.io.IOException; import java.io.InputStream; public class FTPUploadDemo { public static void main(String[] args) { FTPClient client = new FTPClient(); String filename = "data.txt"; // Read the file from the resources folder. ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try (InputStream is = classLoad...
APACHE COMMONS / NOTES</>↗Apache Commons11 Jul 2008
This example demonstrates how to download a file from FTP server. To download a file, we first connect to the FTP server and then login by supplying the username and password. To download the file we call retrieveFile() method of the FTPClient object. This method takes two parameters, the remote filename and an OutputStream of […]
APACHE COMMONS / NOTES</>↗Apache Commons10 Jul 2008
The File Transfer Protocol (FTP) is a standard network protocol used to transfer computer files between a client and server on a computer network. The example below shows you how to connect to an FTP server. In this example we are using the FTPClient class of the Apache Commons Net library. To connect to the […]
APACHE COMMONS / NOTES</>↗Apache Commons10 Jul 2008
This example demonstrates a touch command just like Unix touch command. If the file to be touched doesn’t exist, a new empty file will be created. package org.kodejava.commons.io; import org.apache.commons.io.FileUtils; import java.io.File; import java.io.IOException; public class TouchFileExample { public static void main(String[] args) { try { File file = new File("Touch.dat"); // Touch the file. […]