久久久久久久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(使用線程逐塊處理文件)
主站蜘蛛池模板: 国产精品美女www爽爽爽 | 午夜视频网 | 久久久久亚洲视频 | 在线视频国产一区 | 亚洲成人午夜电影 | a国产视频 | 日本三级在线 | 国产一级一级国产 | 日本久草| 国产免费一区二区 | 久久久精品视频一区二区三区 | 国内自拍真实伦在线观看 | 欧美日韩久久精品 | 自拍偷拍亚洲欧美 | 欧美黄色网络 | 中文字幕av在线播放 | 日韩av在线免费 | 日韩精品一区二区三区 | 中文字幕一级 | 黄网免费看 | 国产欧美一区二区三区日本久久久 | 欧美激情精品久久久久久 | 亚洲人成在线播放 | 91av导航| 欧美日韩综合一区 | 午夜精品视频在线观看 | 亚洲精品一二三 | 成人国产免费观看 | 精品一区二区三区四区在线 | 日韩免费视频一区二区 | 久久精品欧美视频 | 国产乱码精品一区二三赶尸艳谈 | 国产亚洲一区二区三区在线观看 | 成人午夜电影在线观看 | 美女亚洲一区 | 午夜丁香视频在线观看 | 国产精品久久久久久久久久久久 | 国产精品夜色一区二区三区 | 九九亚洲精品 | 欧美a区 | 成人av网站在线观看 |