<server>
<id>ftp-server</id>
<username>your-username</username>
<password>your-password</password>
<configuration>
<server>ftp://ftp.example.com</server>
<port>21</port>
<timeout>10000</timeout>
<passiveMode>false</passiveMode>
</configuration>
</server>
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.WagonException;
import org.apache.maven.wagon.providers.ftp.FtpWagon;
import org.apache.maven.wagon.providers.ftp.FtpWagonConstants;
import org.apache.maven.wagon.repository.Repository;
public class FtpExample {
public static void main(String[] args) {
try {
Wagon wagon = new FtpWagon();
Repository repository = new Repository("ftp-server", "ftp://ftp.example.com");
wagon.connect(repository, createAuthenticationInfo());
File fileToUpload = new File("path/to/file");
String uploadPath = "/remote/path";
wagon.put(fileToUpload, uploadPath);
String downloadPath = "/remote/path/to/file";
File localFile = new File("path/to/save/file");
wagon.get(downloadPath, localFile);
wagon.disconnect();
e.printStackTrace();
}
}
private static AuthenticationInfo createAuthenticationInfo() {
AuthenticationInfo authenticationInfo = new AuthenticationInfo();
authenticationInfo.setUserName("your-username");
authenticationInfo.setPassword("your-password");
return authenticationInfo;
}
}