| π Articles | π€ My Profile |
SFTP stands for Secure File Transfer Protocol (also known as SSH File Transfer Protocol).
β¨ It is a network protocol used to transfer files securely over a protected channel.
π Unlike FTP (File Transfer Protocol), which sends data (including usernames and passwords) in plain text,
π SFTP encrypts both commands and data using SSH (Secure Shell), making it much more secure.
πβ‘οΈπ File moves safely from one system to another with full encryption.
| Feature | FTP (File Transfer Protocol) | FTPS (FTP Secure) | SFTP (SSH File Transfer Protocol) |
|---|---|---|---|
| Security | No encryption (plain text) | SSL/TLS encryption | SSH encryption (very secure) |
| Port | 21 (plus random data ports) | 21 (plus TLS/SSL) | 22 (single port) |
| Auth | Username + Password | Username + Password + Certs | Username + Password / SSH keys |
| Protocol | FTP only | FTP + TLS | Built on SSH |
Connection Initialization
Example:
sftp user@server.com
Authentication
The server authenticates the client using either:
.pem or .ppk files).Keys are more secure because the private key never leaves your machine.
Secure Channel Setup
File Operations
Over the secure tunnel, the client can issue commands like:
ls β list filescd β change directoryget file.txt β download fileput report.csv β upload fileUnlike FTP, these commands and the file contents are encrypted.
Integrity & Acknowledgement
Disconnection
Example:
bye
π₯οΈ Example in Action (Linux/Windows Command Line)
# Connect to SFTP server
sftp -i ~/.ssh/id_rsa user@host.com
# Inside SFTP prompt
sftp> ls
sftp> cd /remote/path
sftp> put localfile.txt
sftp> get remotefile.csv
sftp> bye
π In short: SFTP works by combining SSH security + file transfer commands in one protocol, so every action and data packet is encrypted and safe.
In enterprise systems, you often need to:
Spring Boot applications integrate with SFTP servers to handle these scenarios.
π¦ Library for SFTP in Spring Boot
We use JSch (Java Secure Channel) library:
<dependency>
<groupId>com.github.mwiede</groupId>
<artifactId>jsch</artifactId>
<version>0.2.17</version>
</dependency>
π₯οΈ Backend
π API Documentation
π’οΈ Database
π File Transfer (SFTP)
π οΈ Build & Dependency Management
βοΈ Utilities
@Getter, @Setter, @Builder, etc.)spring-boot-sftp-integration
βββ π src/
β βββ π main/
β βββ π java/
β β βββ π com/sahu/springboot/basics/
β β βββ π config/
β β β βββ π OpenApiConfig.java
β β β βββ π OpenApiProperties.java
β β β
β β βββ π constant/
β β β βββ π ApiStatus.java
β β β βββ π AppConstants.java
β β β βββ π AuthenticationType.java
β β β βββ π KeyFormat.java
β β β
β β βββ π controller/rest/
β β β βββ π SftpConfigRestController.java
β β β βββ π SftpFileRestController.java
β β β βββ π SftpKeyUtilRestController.java
β β β
β β βββ π dto/
β β β βββ π ApiResponse.java
β β β βββ π SftpConfigRequest.java
β β β βββ π SftpConfigResponse.java
β β β βββ π SftpDirectoryResponse.java
β β β
β β βββ π exception/
β β β βββ π GlobalExceptionHandler.java
β β β βββ π InvalidSftpKeyFileException.java
β β β βββ π SftpConfigAlreadyExistException.java
β β β βββ π SftpConfigNotFoundException.java
β β β βββ π SftpException.java
β β β
β β βββ π model/
β β β βββ π SftpConfig.java
β β β
β β βββ π operation/
β β β βββ π SftpConnectionHandler.java
β β β
β β βββ π repository/
β β β βββ π SftpConfigRepository.java
β β β
β β βββ π service/
β β β βββ π impl/
β β β β βββ π FileReaderServiceImpl.java
β β β β βββ π SftpConfigServiceImpl.java
β β β β
β β β βββ π util/
β β β β βββ π SftpConfigUtil.java
β β β β
β β β βββ π FileReaderService.java
β β β βββ π SftpConfigService.java
β β β
β β βββ π util/
β β β βββ π AseCryptUtil.java
β β β βββ π SftpKeyConvertorUtil.java
β β β
β β βββ π validation/
β β β βββ π PortValidator.java
β β β βββ π RemoteDirectoryValidator.java
β β β βββ π SftpConfigAuthValidator.java
β β β βββ π ValidPort.java
β β β βββ π ValidRemoteDirectory.java
β β β βββ π ValidSftpConfigAuth.java
β β β
β β βββ π SpringBootSftpIntegrationApplication.java
β β
β βββ π resources/
β βββ π application.yml
β
βββ π docker-compose.yml
βββ π pom.xml
You can find the complete code repository for this project on GitHub:
1οΈβ£ π³ Using Docker Compose (for MySQL container)
docker-compose up -d
β
This starts MySQL in a container (-d = detached mode).
π Verify with:
docker ps
π DB is now available at localhost:3307.
π Credentials (username, password, DB name) are in docker-compose.yml.
2οΈβ£ π» Run Directly in IntelliJ IDEA
SpringBootSftpIntegrationApplication.java3οΈβ£ β‘ Run with Maven Command (CLI)
βΆοΈ Run app:
mvn spring-boot:run
π Run app with debug mode:
mvn spring-boot:run -Dspring-boot.run.fork=false -Dmaven.surefire.debug
π¦ Build JAR and run:
mvn clean package -DskipTests
java -jar target/spring-boot-sftp-integration-0.0.1-SNAPSHOT.jar
For a detailed running and demonstration of the application walkthrough,
watch the following YouTube video: