I want to connect to an FTP server and transfer a file with Java. I could not find anything about secure FTP.Can anybody help me about this?

I also want to ask that if i can connect to an FTP server using SSL with command line. If i can connect with command line;can not I connect with executing command line arguments embedded in my Java code?

Thanks for information.

Dani AI

Generated

Quick summary and practical path forward (ties to earlier replies by , , and ):

There are two different secure file‑transfer families in common use; they are not interchangeable, so first confirm which the server exposes (check server docs or test with a client). Once the protocol is known, follow a small checklist: pick a Java library that implements that protocol, verify authentication method (password vs key/cert), test with an interactive client to confirm connectivity and credentials, then implement the transfer in Java.

Recommendations for Java-side work

  • For SSH‑based transfers use a mature SSH library (JSch or SSHJ). For TLS/TLS‑wrapped FTP use a library that explicitly supports TLS for FTP (Apache Commons Net is a commonly used option). Java’s built‑in URL handlers do not provide full, production‑grade secure FTP handling.
  • Prefer host‑key or certificate verification and key‑based authentication in production. Do not hardcode credentials in source; use a keystore, environment variables, or a secrets manager.
  • Invoking a command‑line client from Java (ProcessBuilder) is possible for quick scripts, but it’s brittle (escaping, error parsing, platform differences) and not recommended for robust systems.

Minimal example: SFTP upload with JSch

import com.jcraft.jsch.*;

JSch jsch = new JSch();
Session session = jsch.getSession("user","host",22);
session.setPassword("pass");
java.util.Properties cfg = new java.util.Properties();
cfg.put("StrictHostKeyChecking","no"); // only for testing
session.setConfig(cfg);
session.connect();
ChannelSftp sftp = (ChannelSftp) session.openChannel("sftp");
sftp.connect();
sftp.put("/local/path/file.txt", "/remote/path/file.txt");
sftp.disconnect();
session.disconnect();

Troubleshooting and security notes

  • Enable library debug/logging to see handshake and auth failures.
  • Firewalls and NAT can affect FTP/TLS data channels; SSH/SFTP tends to be simpler through firewalls because it uses a single connection.
  • Never disable strict host/cert checks in production; use a proper truststore/known_hosts.
    Following these steps produces a stable, auditable transfer flow that avoids fragile command‑line wrapping and keeps credentials and host verification under control.

Recommended Answers

All 3 Replies

What does Google say about secure FTP? Does it exist?

If you are using Windows 2008 server (IIS7) then it supports FTP over Secure Socket Layer (SSL). This feauture allows to be encrypted between an FTP client and server.
You can use FTP clients like filezilla which supports FTP over SSL.

first, you must make sure that your FTP server supports FTPS. There are two kinds, implicit and explicit SSL that run on ports 21 and 990 respectively. Second, you need to use a Java FTP library that supports FTPS. Secure FTP Factory supports FTP, FTPS and SFTP protocols.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.