久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

通過 FTP 在 Java 中上傳文件

File upload in Java through FTP(通過 FTP 在 Java 中上傳文件)
本文介紹了通過 FTP 在 Java 中上傳文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試開發一個簡單的 java 代碼,它將一些內容從本地機器上傳到服務器/另一臺機器.我使用了下面的代碼

Im trying to develop a simple java code which will upload some contents from local machine to a server/another machine.I used the below code

import sun.net.ftp.*;
import java.io.*;

public class SftpUpload {
 public static void main(String args[]) {
   String hostname = "some.remote.machine"; //Remote FTP server: Change this
   String username = "user"; //Remote user name: Change this
   String password = "start123"; //Remote user password: Change this
   String upfile = args[0]; //File to upload passed on command line
   String remdir = "/home/user"; //Remote directory for file upload
   FtpClient ftp = new FtpClient();
   try {
      ftp.openServer(hostname); //Connect to FTP server
      ftp.login(username, password); //Login
      ftp.binary(); //Set to binary mode transfer
      ftp.cd(remdir); //Change to remote directory
      File file = new File(upfile);
      OutputStream out = ftp.put(file.getName()); //Start upload
      InputStream in = new FileInputStream(file);
      byte c[] = new byte[4096];
      int read = 0;
      while ((read = in.read(c)) != -1 ) {
         out.write(c, 0, read);
      } //Upload finished
      in.close();
      out.close();
      ftp.closeServer(); //Close connection
   } catch (Exception e) {
      System.out.println("Error: " + e.getMessage());
   }
 }
}

但它在第 11 行顯示錯誤為無法實例化 FtpClient 類型".誰能幫我解決一下.

But it is showing error in Line 11 as 'Cannot instantiate the type FtpClient'. Can some one help me how to rectify it.

推薦答案

你不能實例化它,因為 sun.net.ftp.FtpClient 是抽象類.

You cannot instantiate it because sun.net.ftp.FtpClient is abstract class.

我建議使用 Apache Commons Net 而不是使用 sun.x 包.FTP客戶端示例可以從這里找到.

I suggest using Apache Commons Net instead of playing with sun.x packages. FTP client example can be found from here.

這篇關于通過 FTP 在 Java 中上傳文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 国产精品一线 | 欧美日韩在线免费观看 | 国产亚洲一区二区三区 | 91日韩在线 | 草逼视频免费看 | 触手繁殖の地狱3d啪啪 | 欧美女同视频 | 永久免费av网站 | 国产精品入口夜色视频大尺度 | 九九久久精品视频 | 亚洲无人区一线二线三线 | 欧美在线免费 | 在线观看黄色片 | 久久久网| 一区二区小视频 | 欧美日韩亚洲一区 | 色噜噜狠狠一区二区三区果冻 | av在线日韩 | 免费在线毛片 | 伊人91| 久久av一区二区 | 国产精品久久久久久妇女6080 | 亚洲综合伊人 | 久久久97 | 欧美在线观看一区二区 | 精品国产一二三 | 成人自拍视频在线观看 | 免费国产一区 | 国产一级在线 | 久久精品国产77777蜜臀 | 色综合av| 精品蜜桃一区二区三区 | 久久精品久久久 | 天天干天天曰 | 又黄又爽的网站 | 日本三级大片 | 久精品视频 | 国产区免费 | 91在线精品李宗瑞 | 久久综合影院 | 天美传媒在线观看 |