Search code examples
javaftpapache-commons-net

Create an empty file on FTP server in Java


I need some Java way alike bash touch-command on FTP – create an empty file on FTP server with org.apache.commons.net.ftp.FTPClient (or another library).


Solution

  • Upload an empty "in-memory file", like this:

    InputStream bin = ByteArrayInputStream(new byte[0]);
    ftpClient.storeFile("/remote/path/emptyfile", bin);