當前位置:首頁 » 文件管理 » ftp目錄配置

ftp目錄配置

發布時間: 2022-10-14 21:15:07

ftp的路徑怎麼設置

問一下,你是想做ftp上傳下載么?

首先你需要安裝一個ftp服務端程序,啟動起來,然後下載一個ftp客戶端程序,測試能不能連接,首先這一塊兒需要測試通過。
代碼ftp上傳下載
2.1 上傳代碼:
import java.io.File;
import java.io.FileInputStream;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;

public class test {

private FTPClient ftp;
/**
*
* @param path 上傳到ftp伺服器哪個路徑下
* @param addr 地址
* @param port 埠號
* @param username 用戶名
* @param password 密碼
* @return
* @throws Exception
*/
private boolean connect(String path,String addr,int port,String username,String password) throws Exception {
boolean result = false;
ftp = new FTPClient();
int reply;
ftp.connect(addr,port);
ftp.login(username,password);
ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
return result;
}
ftp.changeWorkingDirectory(path);
result = true;
return result;
}
/**
*
* @param file 上傳的文件或文件夾
* @throws Exception
*/
private void upload(File file) throws Exception{
if(file.isDirectory()){
ftp.makeDirectory(file.getName());
ftp.changeWorkingDirectory(file.getName());
String[] files = file.list();
for (int i = 0; i < files.length; i++) {
File file1 = new File(file.getPath()+"\\"+files[i] );
if(file1.isDirectory()){
upload(file1);
ftp.changeToParentDirectory();
}else{
File file2 = new File(file.getPath()+"\\"+files[i]);
FileInputStream input = new FileInputStream(file2);
ftp.storeFile(file2.getName(), input);
input.close();
}
}
}else{
File file2 = new File(file.getPath());
FileInputStream input = new FileInputStream(file2);
ftp.storeFile(file2.getName(), input);
input.close();
}
}
public static void main(String[] args) throws Exception{
test t = new test();
t.connect("", "localhost", 21, "yhh", "yhhazr");
File file = new File("e:\\uploadify");
t.upload(file);
}
}
2.2 下載代碼
這里沒有用到filter,如果用filter就可以過濾想要的文件。

public class Ftp {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Ftp ftp = new Ftp();
String hostname = "www.strawberry.com";
Integer port = 21;
String username = "username";
String password = "password";
String remote = "/c.txt";
String local = "/home/tin/LeonChen/FTP/";
try {
ftp.connect(hostname, port, username, password);
System.out.println("接收狀態:"+ftp.download(remote, local));
ftp.disconnect();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

private FTPClient ftpClient = new FTPClient();

/*
* * 連接到FTP伺服器
* * @param hostname 主機名
* * @param port 埠
* * @param username 用戶名
* * @param password 密碼
* * @return 是否連接成功
* * @throws IOException
*/
private boolean connect(String hostname, int port, String username,
String password) throws IOException {
ftpClient.connect(hostname, port);
ftpClient.setControlEncoding("UTF-8");
if (FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
if (ftpClient.login(username, password)) {
return true;
}
}
disconnect();
return false;
}

/*
* 從FTP伺服器上下載文件,支持斷點續傳,上傳百分比匯報
*
* @param remote 遠程文件路徑
*
* @param local 本地文件路徑
*
* @return 上傳的狀態
*
* @throws IOException
*/
public DownloadStatus download(String remote, String local)
throws IOException {
// 設置被動模式
ftpClient.enterLocalPassiveMode();
// 設置以二進制方式傳輸
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
DownloadStatus result;
// 檢查遠程文件是否存在
FTPFile[] files = ftpClient.listFiles(new String(remote
.getBytes("UTF-8"), "iso-8859-1"));
if (files.length != 1) {
System.out.println("遠程文件不存在");
return DownloadStatus.Remote_File_Noexist;
}
long lRemoteSize = files[0].getSize();
String fildName = files[0].getName();
// 本地存在文件,進行斷點下載
File f = new File(local+fildName);
if (f.exists()) {
long localSize = f.length();
if (localSize >= lRemoteSize) {
System.out.println("本地文件大於遠程文件,下載中止");
return DownloadStatus.Local_Bigger_Remote;
}

// 進行斷點續傳,並記錄狀態
FileOutputStream out = new FileOutputStream(f, true);
ftpClient.setRestartOffset(localSize);
InputStream in = ftpClient.retrieveFileStream(new String(remote.getBytes("UTF-8"), "iso-8859-1"));
byte[] bytes = new byte[1024];
long step = lRemoteSize / 100;
long process = localSize / step;
int c;
while ((c = in.read(bytes)) != -1) {
out.write(bytes, 0, c);
localSize += c;
long nowProcess = localSize / step;
if (nowProcess > process) {
process = nowProcess;
if (process % 10 == 0)
System.out.println("下載進度:" + process);
// TODO 更新文件下載進度,值存放在process變數中
}
}
in.close();
out.close();
boolean isDo = ftpClient.completePendingCommand();
if (isDo) {
result = DownloadStatus.Download_From_Break_Success;
} else {
result = DownloadStatus.Download_From_Break_Failed;
}
} else {
OutputStream out = new FileOutputStream(f);
InputStream in = ftpClient.retrieveFileStream(new String(remote.getBytes("UTF-8"), "iso-8859-1"));
byte[] bytes = new byte[1024];
long step = lRemoteSize / 100;
long process = 0;
long localSize = 0L;
int c;
while ((c = in.read(bytes)) != -1) {
out.write(bytes, 0, c);
localSize += c;
long nowProcess = localSize / step;
if (nowProcess > process) {
process = nowProcess;
if (process % 10 == 0)
System.out.println("下載進度:" + process);
// TODO 更新文件下載進度,值存放在process變數中
}
}
in.close();
out.close();
boolean upNewStatus = ftpClient.completePendingCommand();
if (upNewStatus) {
result = DownloadStatus.Download_New_Success;
} else {
result = DownloadStatus.Download_New_Failed;
}
}
return result;
}

private void disconnect() throws IOException {
if (ftpClient.isConnected()) {
ftpClient.disconnect();
}
}

}

linux里ftp伺服器怎麼配置根目錄

1、deepin linux默認沒有安裝命令行的ftp客戶端,在終端執行ftp命令會提示未找到命令。

❸ linux里ftp伺服器怎麼配置根目錄

在linux的vsftp配置文件下添加
本地的根目錄是添加
local
root
=
/tmp/ftp/pub
就把local的目錄改變了成
/tmp/ftp/pub
匿名的根目錄是添加
anon
root
=
/tmp/ftp/pub
就把匿名的目錄改變了成
/tmp/ftp/pub
順便的目錄都行

❹ 華為防為牆如何配置ftp

配置FW作為FTP伺服器

介紹配置FW作為FTP伺服器的方法。

操作步驟

  • 執行命令system-view,進入系統視圖。

  • 執行命令ftp server enable,啟動FTP伺服器。

  • 創建FTP管理員。

  • 執行命令aaa,進入AAA視圖。

  • 執行命令manager-useruser-name,配置管理員賬號並進入管理員視圖。

  • 執行命令password[ciphercipher-password],配置管理員賬號對應的密碼。

    說明:

    薦採用互動式方式創建管理員密碼,通過ciphercipher-password配置密碼時存在密碼泄露的危險。

  • 執行命令levellevel,配置管理員的級別。

    說明:

    為了保證管理員能正常登錄設備,請將管理員級別配置在3級或3級以上。

  • 執行命令service-typeftp,配置管理員擁有的服務類型為FTP。

  • 執行命令ftp-directorydirectory,配置管理員賬號的FTP服務目錄。

  • 執行命令access-limitmax-number,配置使用本管理員賬號同時可登錄的最大管理員數量。

  • 執行命令quit,退回到AAA視圖。

  • 執行命令quit,退回到系統視圖。

  • 可選:執行命令ftp timeoutminutes,配置FTP伺服器超時斷連時間。

    為了防止未授權者的非法入侵,如果在一定時間內沒有收到FTP管理員的服務請求,則系統會斷開與該FTP客戶端的連接。當FTP管理員再需要服務時,需要重新進行登錄操作。

    預設情況下,系統的連接空閑時間為30分鍾。

  • 可選:配置FTP的訪問控制列表。

    通過配置FTP訪問控制列表,可提高FTP伺服器的安全性。

  • 執行命令acl[number]acl-number[vpn-instancevpn-instance],進入ACL視圖。

    說明:

    FTP只支持基本訪問控制列表,因此acl-number的取值范圍是2000~2999。

  • 執行命令rule[rule-id] {deny|permit} [logging|source{source-ip-address soucer-wildcard|any} |time-rangetime-name],配置ACL規則。

  • 執行命令quit,退回到系統視圖。

  • 執行命令ftp aclacl-number,配置FTP基本訪問控制列表。

❺ 紫光軟體怎麼設置ftp存儲目錄

摘要 紫光是業內的綜合性專業性較強的企業,他的很多檔案管理內容都是標準的,也就是說,會在傳統的檔案館或者事業單位匹配度比較高,但另外一個角度來說,他的產品研發較早,系統功能雖然穩定,但界面和操作,跟當前的輕雲操作,似乎有些背道而馳,更何況他的價格會比較高一些,至於量子偉業,多年的老品牌,無論是功能還是界面以及後期擴展,個人認為都是要好於紫光的,最後說說致得,個人覺得,產品功能相對完善,但界面操作並不是很友好,人工上手速度較慢,當然,如果看在他相對合適的價格,這些問題都是可以忍受的。

❻ Windows Server 2008 R2 架設FTP伺服器並配置訪問多個不同的目錄

1、 進入【控制面板】ー>【管理工具】ー>Internet信息服務(IIS);
2、 雙擊【默認FTP站點】,在右側菜單中配置FTP主目錄、登錄賬戶、操作許可權等;
3、右擊【默認FTP站點】ー>【添加虛擬目錄】,設置虛擬目錄名稱,此名稱可以隨便寫,若要設置多個虛擬目錄,注意多個虛擬目錄的名稱不要重復;
4、設置虛擬目錄實際對應的物理路徑;
5、 顯示虛擬目錄(重要) :此時進入FTP主目錄下是看不到添加的虛擬目錄的,若要能在主目錄下訪問並能操作虛擬目錄, 需在主目錄文件夾下創建一個與前面設置的虛擬目錄別名同名的空文件夾 , 重新登錄FTP即可發現主目錄中多出來添加的虛擬目錄;
6、對虛擬目錄內的這些文件操作時,實際上是對虛擬目錄的操作。

❼ 如果配置ftp虛擬目錄

我也建議用
serv-u
來做FTP
windows下做,一些許可權不太好設置麻煩
serv-u
里設置虛擬目錄要在兩個地方設置
1.在你建立的帳號下要添加這個目錄的許可權
2.在你建立的這個fTP名稱下
設置項目里有個
虛擬路徑的,在這里把你要添加的目錄寫好,添加到主目錄里,並取個名稱就好了

❽ 交換機FTP怎麼配置

1.先打開FTP
2.配置FTP登陸用戶
3.配置用戶許可權
4.配置用戶類型
5.配置FTP目錄
下面以華為交換機AA用戶密碼為1234567890為例
#
ftp server enable
#
aaa
local-user aa password cipher 1234567890
local-user aa privilege level 15
local-user aa ftp-directory flash:
local-user aa service-type ftp

熱點內容
在團競模式中怎麼重置配置 發布:2024-10-08 02:12:54 瀏覽:288
寶馬遠程伺服器如何啟用 發布:2024-10-08 02:02:57 瀏覽:390
c語言freadfwrite 發布:2024-10-08 02:01:15 瀏覽:853
腳本還不簡單嗎 發布:2024-10-08 01:54:43 瀏覽:422
安卓手機如何像平板一樣橫屏 發布:2024-10-08 01:33:26 瀏覽:509
wapi認證伺服器ip 發布:2024-10-08 01:33:24 瀏覽:506
centos自帶python 發布:2024-10-08 00:53:31 瀏覽:340
android串口調試助手 發布:2024-10-08 00:45:03 瀏覽:405
sqlserver2008亂碼 發布:2024-10-08 00:39:59 瀏覽:220
華為電腦伺服器系統進不去提示 發布:2024-10-08 00:13:42 瀏覽:491