2016-04-28 12 views
0
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();  
}  

を使用してのUbuntu Serverに接続する:「FtpProtocolException:ウェルカムメッセージ...」私はすべての有効な資格情報を提供してきたが、私は例外を取得しています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例外:無効なユーザ名/パスワード

+0

ポート22がデフォルトのFTPポートが間違っているようです。 – Sanjeev

答えて

1

FTPプロトコルを使用してSSH/SFTPポート22に接続しています。

これは動作しません。

  • FTPを使用する場合は、実際には、SFTPを使用してSFTPクライアントを使用したい場合は、標準のFTPポート21
  • に接続します。
    How to retrieve a file from a server via SFTP?を参照してください。
+0

ありがとうございます! Martin ...上のリンクで与えられた例Java:私のために働いたサーバーからファイルをSFTPする最良の方法は何ですか? –

+0

ようこそ。 StackOverflowで我々は[答えを受け入れることで感謝](http://stackoverflow.com/help/someone-answers)。 –

関連する問題