خرید بک لینک

Vote count: 0

Am trying to upload file to remote folder from local folder.But am getting an error, I don't know where I made a mistake. I hope someone helps to find the solution. Thanks.

The code given below:

public static void main(String[] args) {
        String server = "www.xyz.com";
        int port = 22;
        String user = "user";
        String pass = "admin@12";

        FTPClient ftpClient = new FTPClient();
        try {

            ftpClient.coect(server, port);
            System.out.println("1");
            ftpClient.login(user, pass);
            System.out.println("2");
            ftpClient.enterLocalPassiveMode();

            System.out.println("3");

            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
            System.out.println("4");

            // APPROACH #1: uploads first file using an InputStream
            File firstLocalFile = new File("D:/UploadServlet.java");

            String firstRemoteFile = "Projects.zip";
            InputStream inputStream = new FileInputStream(firstLocalFile);

            System.out.println("Start uploading first file");
            boolean done = ftpClient.storeFile(firstRemoteFile, inputStream);
            inputStream.close();
            if (done) {
                System.out.println("The first file is uploaded successfully.");
            }



        } catch (IOException ex) {
            System.out.println("Error: " + ex.getMessage());
            ex.printStackTrace();
        } finally {
            try {
                if (ftpClient.isCoected()) {
                    ftpClient.logout();
                    ftpClient.discoect();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }

Whenever I execute the code am getting the below error.

Error: Could not parse response code.
Server Reply: SSH-2.0-OpenSSH_4.3
org.apache.commons.net.MalformedServerReplyException: Could not parse response code.
Server Reply: SSH-2.0-OpenSSH_4.3
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:284)
    at org.apache.commons.net.ftp.FTP._coectAction_(FTP.java:335)
    at org.apache.commons.net.ftp.FTPClient._coectAction_(FTPClient.java:550)
    at org.apache.commons.net.SocketClient.coect(SocketClient.java:163)
    at FTPUploadFileDemo.main(FTPUploadFileDemo.java:26)
org.apache.commons.net.MalformedServerReplyException: Could not parse response code.
Server Reply: Protocol mismatch.
    at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:284)
    at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:460)
    at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:520)
    at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:569)
    at org.apache.commons.net.ftp.FTP.quit(FTP.java:781)
    at org.apache.commons.net.ftp.FTPClient.logout(FTPClient.java:706)
    at FTPUploadFileDemo.main(FTPUploadFileDemo.java:58)

asked 52 secs ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 23 ارديبهشت 1395 ساعت: 16:09

صفحه بندی