<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
</dependency>
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.repository.Repository;
import org.apache.maven.wagon.resource.Resource;
import org.apache.maven.wagon.services.Dependencies;
import org.apache.maven.wagon.streaming.StreamingWagon;
import org.apache.maven.wagon.util.IoUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class FTPExample {
public static void main(String[] args) {
Wagon wagon = new StreamingWagon();
Repository repository = new Repository("ftp://your-ftp-url", "ftp");
AuthenticationInfo authenticationInfo = new AuthenticationInfo();
authenticationInfo.setUserName("your-ftp-username");
authenticationInfo.setPassword("your-ftp-password");
wagon.connect(repository, authenticationInfo);
File file = new File("path-to-local-file/filename.txt");
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(file);
Resource resource = new Resource();
resource.setContentLength(file.length());
resource.setName(file.getName());
wagon.put(fileInputStream, resource);
wagon.flush();
e.printStackTrace();
} finally {
IoUtils.close(fileInputStream);
try {
wagon.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}