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

通過 FTP 在 Java 中上傳文件

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

問題描述

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

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.

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

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

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
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 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 日韩欧美不卡 | 久久精品国产a三级三级三级 | 中文区中文字幕免费看 | 欧美激情综合 | 亚洲国产成人精品女人久久久 | 国产精品成人一区二区 | 久在线视频 | 最新中文字幕第一页视频 | 久久综合九九 | 日本一级淫片免费啪啪3 | 久久久久久久网 | 国产在线精品一区二区三区 | 亚洲精品一区在线观看 | 免费福利视频一区二区三区 | 女生羞羞视频 | 欧美在线免费 | 久久久久久亚洲精品不卡 | 国产精品视频一区二区三 | 国产欧美一区二区三区日本久久久 | 91精品久久久久久久久 | 亚洲精品二区 | 在线久草| 在线免费观看亚洲 | 99国内精品久久久久久久 | 91porn成人精品| 在线午夜 | 97av在线 | 在线国产99 | aaa天堂| 伊人久久综合影院 | 欧美一级二级视频 | 99re在线视频| 国产精品不卡一区二区三区 | 国产成人精品一区二区三区网站观看 | 国产成人精品一区二区三区在线观看 | 黄色片在线看 | 亚洲日韩欧美一区二区在线 | 国产成人精品综合 | 亚洲一区国产精品 | 精品av| 亚洲综合一区二区三区 |