JSCAPE
  • Products
    • Managed File Transfer
    • JSCAPE SaaS
    • MFT Gateway
    • MFT Monitor
    • All Products
  • Solutions
    • All Solutions
    • Secure File Transfer
    • AS2 Server Software
    • File Synchronization
    • Reverse Proxy
    • Compliance
    • DMZ Streaming
  • Pricing
  • Company
    • Blog
    • Company
    • Contact Us
    • Clients
    • Case Studies
    • Testimonials
    • Certifications
  • Support
    • Help Desk
    • Documentation
    • Customer Downloads
Get a demo

Secure file transfer with java FTP library

Words by

Charles Ott

When two little kids want to exchange a secret, a lot of negotiation is necessary: “Promise you won’t tell? Cross your heart and hope to die?”. When a client and server computer want to exchange secrets, they need to negotiate too: public keys, encryption methods, ports and more. Fortunately, JSCAPE’s Secure FTP Factory and server…

Published in:

Blog

/

FTP, SFTP

secure file transfer java

When two little kids want to exchange a secret, a lot of negotiation is necessary: “Promise you won’t tell? Cross your heart and hope to die?”. When a client and server computer want to exchange secrets, they need to negotiate too: public keys, encryption methods, ports and more. Fortunately, JSCAPE’s Secure FTP Factory and server software (such as JSCAPE MFT Server) handle most of the details for you.

In the previous article, we discussed insecure transfers using plain, unencrypted FTP. Fortunately, the FTPS (FTP Secure) version is almost identical, except that it can keep a secret. This kind of transfer uses the same SSL (Secure Sockets Layer) protocol used to create https:// web pages. Most of the negotiations, such as choosing a port and an encryption method, are handled automatically and your code does not need to be concerned with them.

One choice you should be aware of is “explicit” versus “implicit” connection type. It’s an easy choice: you want the explicit connection unless it doesn’t work. “Implicit” connections are deprecated and should only be used in some rare circumstances, typically because your server software or firewall doesn’t understand “explicit” connections.

The difference is negotiation. In an “explicit” connection, the client sends a specific command to the server to start the encrypted communications, and the client and the server can then dicker over the encryption type and port used. Like an intransigent Congressman, an “implicit” connection won’t negotiate. It just assumes that the server understands the secure requirements, and it defaults to “well-known” port numbers 990 and 989.

This example uploads GIF images using FTPS. (See the previous article for more explanations of this code.) You’ll note that it’s almost identical to the insecure example except that we create an “Ftps” object instead of an “Ftp” object, and we set the “connectionType” as explained in the comments.

Secure File Upload with FTPS

import com.jscape.inet.ftp.*;
import com.jscape.inet.ftps.*;
import java.io.*;
import java.util.Enumeration;

public class SecureUpload extends FtpAdapter {
    private String hostname;
    private String username;
    private String password;
    
    // perform multiple file upload
    public void doUpload(String hostname, String username, String password) throws FtpException {
        Ftps ftp = new Ftps(hostname,username,password);
        
        //capture Ftps related events
        ftp.addFtpListener(this);
                
                // Set the connection type. Explicit is Ftps.AUTH_TLS. 
                // Implicit (which is deprecated) is Ftps.IMPLICIT_SSL
                ftp.setConnectionType(Ftps.AUTH_TLS);
                
        ftp.connect();
        ftp.setBinary();
        ftp.mupload(".*\\.gif");
        ftp.disconnect();
    }
    
    public static void main(String[] args) {
        String hostname = "ftp.somewebsite.com";
        String username = "IFeelSecure";
        String password = "zip1a2dee3doo4dah";
        try {
            SecureUpload theUploader = new SecureUpload();
            theUploader.doUpload(hostname,username,password);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
}

A secure download is just as easy:

Secure File Download with FTPS

/*
 * SecureDownload.java
 *
 * An example using FTPS.
 */

import com.jscape.inet.ftp.*;
import com.jscape.inet.ftps.*;
import java.io.*;
import java.util.Enumeration;

public class SecureDownload extends FtpAdapter {
    private String hostname;
    private String username;
    private String password;
    private String filter;
    
    // Multiple file downloader from one particular website.
    public void doDownload(String filter) throws FtpException {
        Ftps ftp = new Ftps();
        
        //capture Ftp related events
        ftp.addFtpListener(this);
        ftp.setHostname("ftp.somewebsite.com");
        ftp.setUsername("IFeelSecure");
        ftp.setPassword("zip1a2dee3doo4dah");
        ftp.connect();
        ftp.setBinary();
        ftp.mdownload(filter);
        ftp.disconnect();
    }
    
    public static void main(String[] args) {
        String filter;
        try {
                        filter = ".*\\.gif";
            SecureDownload theDownloader = new SecureDownload();
            theDownloader.doDownload(filter);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
}

With Java FTP Library file transfers, you can protect your username, your password and the contents of the transferred files and you don’t even have to swear “cross my heart and hope to die”!

 

Get a trial.


JSCAPE MFT Server comes with strong authentication, data-at-rest encryption, data loss prevention (DLP), malware protection, high availability, and many more features to support flexible, reliable and secure file transfer operations.

A file transfer solution with extensive security capabilities will help you meet stringent security policies and regulatory compliance requirements. 

Request your risk-free trial here.

Easy To Deploy, Easy To Administer, Easy To Manage

Ready to see how JSCAPE makes managed file transfer so much simpler? Schedule your demo now.

Request a demo

Popular Articles

View more by

JSCAPE
  •  
    1–2 minutes
    23/09/2025

    JSCAPE by Redwood, version 2025.3: New UI continues to make a splash

    Dive back into JSCAPE by Redwood with version 2025.3, bringing more modern UI updates to make using and navigating JSCAPE more intuitive. 

    Read article

  •  
    1–2 minutes
    19/08/2025

    Weathering the economic storm: Expert support is your enterprise file transfer system’s lifeline

    The global economic landscape can be described by one word: “uncertain”. Lingering effects from the 2020 pandemic, combined with new waves of international tariffs throughout 2025, have…

    Read article

  •  
    1–2 minutes
    30/07/2025

    Escape the grip: Why flexible MFT is key to enterprise agility

    Break free from costly vendor lock-in Let’s be blunt: some MFT vendors have built product suites that are less about true partnership and more about proprietary siloing.…

    Read article

  •  
    1–2 minutes
    23/07/2025

    Avoid downtime and threat actors: Getting the best of both worlds in MFT

    For enterprise organizations relying on managed file transfer (MFT) solutions, cybersecurity often feels like an arms race. The need to patch MFT software vulnerabilities to prevent breaches…

    Read article

Related Content

Read more about

JSCAPE MFT
  •  
    1–2 minutes
    30/07/2025

    Escape the grip: Why flexible MFT is key to enterprise agility

    Break free from costly vendor lock-in Let’s be blunt: some MFT vendors have built product suites that are less about true partnership and more about proprietary siloing.…

    Read article

  •  
    1–2 minutes
    03/07/2025

    Consolidate, deploy and thrive: JSCAPE’s formula for MFT success in uncertain times

    Global enterprises today are navigating a landscape marked by significant economic volatility. Fluctuating markets, shifting trade policies and persistent economic uncertainty are compelling enterprise organizations to reevaluate…

    Read article

  •  
    1–2 minutes
    31/03/2025

    SFTP vs. FTPS: Which file transfer software is best for business use?

    What is SFTP? SFTP is a file transfer protocol that’s normally packaged with Secure Shell (SSH), the network protocol most IT administrators use to access and manage…

    Read article

  •  
    1–2 minutes
    25/03/2025

    EDI integration with trading partners: 6 best practices

    Many large companies with high-volume transactions, especially those involved in e-commerce, manufacturing and retail supply chains, have long migrated from manual processes to Electronic Data Interchange (EDI).…

    Read article

Company

  • About Us
  • Contact Us
  • Clients
  • Case Studies
  • Testimonials
  • Privacy Policy
  • Certifications

Resources

  • Managed File Transfer
  • Secure File Transfer
  • Secure FTP Server
  • AS2 Server
  • Reverse Proxy
  • File Upload Processing
  • What Is An AS2 Server?

Support

  • Help Desk
  • Documentation
  • Customer Downloads
JSCAPE

Copyright © 2025 JSCAPE

  • Privacy Policy
  • Cookie Settings