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();
}
I have provided all the valid credentials but I am Getting Exception:
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)
If I remove the port number, its shows me ftpConnection Exception: invalid username/password