this is my code:
String serverAddress = "ftp://ftp.nasdaqtrader.com/symboldirectory/"; // ftp server address
int port = 21; // ftp uses default port Number 21
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect(serverAddress, port);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE/FTP.ASCII_FILE_TYPE);
String remoteFilePath = "/nasdaqtraded.txt";
File localfile = new File(System.getProperty("user.dir")+"\\src\\test\\resources\\stocks.txt");
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(localfile));
boolean success = ftpClient.retrieveFile(remoteFilePath, outputStream);
outputStream.close();
if (success) {
System.out.println("Ftp file successfully download.");
}
} catch (IOException ex) {
System.out.println("Error occurs in downloading files from ftp Server : " + ex.getMessage());
} finally {
try {
if (ftpClient.isConnected()) {
ftpClient.logout();
ftpClient.disconnect();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
And i am running it from localhost so i can download a list of stocks from nasdaq site, problem is it gives me this error:
Error occurs in downloading files from ftp Server : ftp://ftp.nasdaqtrader.com/symboldirectory/: invalid IPv6 address
I understand that is because i am trying to download the file from localhost, is there any way around it?
I am just trying to download this file: ftp://ftp.nasdaqtrader.com/symboldirectory/nasdaqtraded.txt
to my computer, that's it.