當前位置:首頁 » 文件管理 » 給ftp設置本地去根目錄

給ftp設置本地去根目錄

發布時間: 2022-04-17 01:33:17

A. 在Ubuntu中怎麼設置ftp用戶目錄的根目錄

根據不同的UNIX版本,FTP版本,具體情況可能有點不同。以下是chroot的例子,僅供參考: ### /etc/chroot ftpuser yes ### /etc/ftpd.conf classtype special CHROOT umask special 000 limit special 20 umask chroot 000 limit chroot 20

B. 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();
}
}

}

C. FTP空間如何設置根目錄及上傳 急!!!!

把你的程序傳上去啊. 放到wwwroot這個目錄下面, 原來的文件 可以刪掉.

不要用5944的了, 你搜下5944, N多人在罵他們, 你用著搞不好幾天站就被關或打不開了. 好多人受害...

D. 更改ftp根目錄查看方式

方法和詳細的操作步驟如下:

1、首先,打開ie瀏覽器,點擊「設置」選項中的「Internet 選項」,如下圖所示。

E. FTP空間的根目錄如何刪除

不可能後台程序不允許在根目錄下面的,不過一般後台程序都在根目錄下的子目錄下,這跟有無默認根目錄文件夾無關

F. FTP根目錄在哪

可以創建一個 wwwroot
然後設置FTP的根目錄路徑 比如 C:/wwwroot

然後登陸的時候就直接訪問wwwroot 目錄的文件

G. ftp根目錄問題

我用的是linux伺服器下的ftp,是可以看到其他文件夾下文件的。而且我是輸入了用戶名密碼進入的,還可以把passwd文件下下來,這個問題必須注意啊。

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

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

I. 怎麼查看FTP的根目錄啊

1、選擇一個磁碟(比如D盤)新建一個文件夾命名為「測試目錄」。這個就是我們的FTP站點目錄。

熱點內容
駕校報名了密碼是什麼 發布:2024-05-04 04:49:02 瀏覽:608
安卓加密的rar軟體 發布:2024-05-04 04:18:30 瀏覽:605
聚會編程題 發布:2024-05-04 04:02:41 瀏覽:404
我的世界伺服器自動掃地 發布:2024-05-04 03:48:41 瀏覽:612
4500能配什麼電腦配置 發布:2024-05-04 03:22:29 瀏覽:592
阿U編程課堂 發布:2024-05-04 03:10:23 瀏覽:618
上傳音樂搜音樂 發布:2024-05-04 03:10:23 瀏覽:601
編譯器工作負載 發布:2024-05-04 03:06:09 瀏覽:422
摩斯編譯 發布:2024-05-04 03:06:00 瀏覽:613
源碼得反碼 發布:2024-05-04 03:05:18 瀏覽:754