使用Java连接到Ubuntu Server时出现“FtpProtocolException:Welcome message ...”

时间:2016-04-28 14:38:03

标签: java ftp

jquery 1.9.1 & jquery ui 1.9.2

我提供了所有有效的凭据,但我得到了例外:

String ftpUrl = "ftp://%s:%s@%s/%s;type=i";    
String host = "10.88.195.43:22";    
String user = "ionadmin";    
String pass = "ionadmin";    
String filePath = "D:\\JARS\\beforeRunSanity.txt";    
String uploadPath = "/home/ionadmin/";    
ftpUrl = String.format(ftpUrl, user, pass, host, uploadPath);    
System.out.println("Upload URL: " + ftpUrl);    
try {    
    URL url = new URL(ftpUrl);    
    URLConnection conn = url.openConnection();    
    OutputStream outputStream = conn.getOutputStream();    
    FileInputStream inputStream = new FileInputStream(filePath);    
    byte[] buffer = new byte[BUFFER_SIZE];    
    int bytesRead = -1;    
    while ((bytesRead = inputStream.read(buffer)) != -1) {    
        outputStream.write(buffer, 0, bytesRead);    
    }    
    inputStream.close();    
    outputStream.close();    
    System.out.println("File uploaded");    
} catch (IOException ex) {    
    ex.printStackTrace();    
}    

如果我删除了端口号,它会显示ftpConnection异常:用户名/密码无效

1 个答案:

答案 0 :(得分:1)

您正在使用FTP协议连接到SSH / SFTP端口22.

那不行。