java remote file exception

wsyy used Ask the Experts™

I am using ftp to get a remote file, and some exception occurred: Welcome message: SSH-2.0-OpenSSH_4.3

My code is as follow:

public static void main(String[] args) {
            URL url;
            URLConnection connection;
            String urlString = "ftp://root:test123456@";
            String matchString = "name";
            String inputLine;
            BufferedReader inStream;

            try {
                  url = new URL(urlString);
            } catch (MalformedURLException e) {
                  System.err.println("Exception: " + e);
            try {
                  connection = url.openConnection();
                  inStream = new BufferedReader(new InputStreamReader(
                  while (null != (inputLine = inStream.readLine())) {
                        if (inputLine.indexOf(matchString) >= 0) {
            } catch (IOException e) {
                  System.err.println("Exception: " + e);

Please help.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

I would guess you should be using sftp. Ftp is deprecated and best practice is not to use it at all. The most obvious and easy thing to try is

String urlString = "sftp://root:test123456@";

Open in new window

but i've no idea if that's supported or will work

You could also try scp
That error is telling you that you are trying to connect to an SFTP server. SFTP and FTP are completely different protocols.

Here is an article explaining the difference:

You have three options:

1. See if that server allows FTP connections (most likely on port 21)

2. Use a Java library that supports making an SFTP connection

3. Use a 3rd party solution which supports SFTP to automate the file transfer

For example, you can use Robo-FTP ( to manage making the connection and uploading / downloading files. You can call Robo-FTP from your program and have Robo-FTP pass back custom exit codes to tell your program the results of the session (success / failure).


Now, I have changed to use zehon to connect to the server. The exception now is:

Thank you for using Zehon software (  
Please go to to provide us your feedback about the product.
Please go to to submit bugs or feature requests.
220 (vsFTPd 2.0.5)
234 Proceed with negotiation.
USER root
530 Permission denied.
com.zehon.exception.FileTransferException: com.zehon.exception.FileTransferException: java.lang.NullPointerException
      at com.zehon.FileTransferClient.getFile(
      at com.zehon.ftps.FTPsClient.getFile(
      at com.zehon.ftps.FTPs.getFile(
Caused by: com.zehon.exception.FileTransferException: java.lang.NullPointerException
      at com.zehon.ftps.FTPsClient.getFileAsStream(
      at com.zehon.FileTransferClient.getFile(
      ... 3 more
Caused by: java.lang.NullPointerException
      at com.zehon.ftps.FTPsClient.getFileAsStreamHelper(
      at com.zehon.ftps.FTPsClient.getFileAsStream(
      ... 4 more

What does it mean? I am using root account to connect? Why does a permission error occur?
I do not think you will be able to ftp with the user 'root' . Instead use an account that has root privileges . First try to FTP with your user account to eliminate  possibility of problem from the java program itself
Top Expert 2016
Yes, you need to check carefully that the credentials are correct.

It's a security no-no to allow root login, especially remotely, so it's unlikely, as sharonseth says, that 'root' will work.

You might also look at the API - it's not a very good sign of quality if improper authentication causes NPEs

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial