String ftpUrl = "ftp://%s:%[email protected]%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();
}
我已經提供了所有的有效憑據,但我得到異常時:「FtpProtocolException:歡迎信息...」連接到Ubuntu的服務器使用Java
Exception in thread "main" java.io.IOException: sun.net.ftp.FtpProtocolException: Welcome message: SSH-2.0-OpenSSH_6.6p1 Ubuntu-2ubuntu1
at sun.net.www.protocol.ftp.FtpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.ftp.FtpURLConnection.getOutputStream(Unknown Source)
如果我刪除的端口號,其顯示我ftpConnection例外:無效的用戶名/密碼
端口22似乎是錯誤的默認FTP端口是21 – Sanjeev