Even though there is truth in that classes in sun.*
should be avoided, the answer does not address the error appropriately, besides suggesting an alternative.
I don't have a scope on the context in which you are trying to instantiate sun.net.ftp.FtpClient
- but it is still possible to do so.
The class is abstract, so you can't instantiate it. (See §8.1.1.1)
All is not lost though.
To get an instance of FtpClient
, you can use the static methods from sun.net.ftp.FtpClientProvider
that is found in the SDK to do so, like in the example below:
...
final FtpClient ftpClient = FtpClientProvider.provider().createFtpClient();
final InetAddress inetAddress = InetAddress.getByName(ftpUrl.getHost());
final int port = ftpUrl.getPort();
final InetSocketAddress socketAddress = new InetSocketAddress(inetAddress, port);
ftpClient.connect(socketAddress);
ftpClient.login(username, password.toCharArray());
...
There is a bit more work involved, but it allows you to avoid adding a new library with heaps of classes that you don't need - it depends on what you want to do.