當前位置:首頁 » 文件管理 » ftp路徑

ftp路徑

發布時間: 2022-01-18 02:56:10

ftp獲取文件名以及文件路徑

既然是伺服器,而且是linux 你用一個tomcat 當做伺服器,可以配置一下tomcat,就可以直接ftp 模式訪問文件夾了。

㈡ 怎麼查看FTP的根目錄啊

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

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

}

㈣ ftp如何直接連接到已有的絕對路徑

方法/步驟
1
第一步,打開IIS,步驟如下:
點擊開始--管理工具--IIS管理器
或者
開始--控制面板--管理工具--IIS管理器

2
第二步,打開IIS後,在右邊選擇FTP並展開,找到找到默認FTP,我們這里就直接用這個默認FTP來設置,當然這個名稱可以改,但這個名稱不是FTP的用戶名;

3
第三步,我們打開默認FTP的屬性面板;

4
第四步,我們點到「FTP站點」選項卡,裡面可以設置FTP的
描述(非帳號)
IP地址(如果是多IP可以指定用哪個IP來鏈接)
TCP埠(鏈接FTP的埠號)

5
第五步,我們進入到「安全帳戶」選項卡,這里要把「允許匿名鏈接」取消,不然人家就直接輸入IP就可以鏈接了;

6
第六步,我們進入到"消息"選項卡,這個裡面一般我們不用設置任何內容,這里就是FTP鏈接時我們看到的一些信息,有需要的可以設置,一般跳過;

7
第七步,我們進入到"主目錄"選項卡,
"本地路徑"我們填上我們需要用FTP訪問的目錄,
"目錄樣式",我們使用默認的就好了

8
第八步,我們進入到"目錄安全性"選項卡,這個我們一般也不用設置,除非你只需要哪個IP可以連到這FTP,那麼可以在這里設置。直接填IP,然後選對應的功能就行了。

9
第九步,我們需要設置FTP訪問的帳號密碼了,右擊默認FTP--許可權--打開許可權設置面板;

10
第十步,打開許可權設置面板後,我們在這里添加一個帳號,這里的帳號要在windows的帳號管理先添加,然後這里才可以添加。給帳號如下許可權就可以了,不建議直接用超級管理員,可以新建一個帳號。這里的帳號就是FTP訪問的帳號,到此就全部設置完成了。

㈤ 用ftp命令下載的文件默認放在哪

樓主您好,ftp下載的文件默認的路徑是您用ftp用戶登錄之後所在的目錄,您可以在用ftp連接上伺服器之後,使用pwd查看路徑。

㈥ 如何得到FTP目錄的物理路徑

首先分析一下同學們提出的普遍問題,即為什麼上課聽得懂,而課下不會作?我作為學理科的教師有這樣的切身感覺:比如讀某一篇文學作品,文章中對自然景色的描寫,對人物內心活動的描寫,都寫得令人叫絕,而自己也知道是如此,但若讓自己提起筆來寫,未必或者說就不能寫出人家的水平來。聽別人說話,看別人文章,聽懂看懂絕對沒有問題,但要自己寫出來變成自己的東西就不那麼容易了。又比如小孩會說的東西,要讓他寫出來,就必須經過反復寫的練習才能達到那一步。因而要由聽懂變成會作,就要在聽懂的基礎上,多多練習,方能掌握其中的規律和奧妙,真正變成自己的東西,這也正是學習高中物理應該下功夫的地方。功夫如何下,在學習過程中應該達到哪些具體要求,應該注意哪些問題,下面我們分幾個層次來具體分析。

㈦ ftp 本地路徑問題。

FTP站點-》右鍵-》新建虛擬目錄(在本地路徑中新建一個文件夾)
完成後從新查看就會發現本地路徑不為空了。

㈧ 怎麼查看FTP伺服器的路徑

都不知道你到底要問什麼.

㈨ ftp文件路徑問題

不是太明白你所說的「路徑」是什麼意思?是ftp路徑?還是網站訪問路徑?
如果是ftp路徑,你的截圖裡面的路徑就是頂級目錄/1.txt。

如果你是問的網站路徑,請看下文:
你在FlashFXP軟體中嘗試雙擊一下「上級目錄」,看看是否能訪問上級目錄。如果不能訪問上級目錄,那麼當前目錄就是頂級目錄。但是網站的默認指向目錄一般不是頂級目錄,一般是頂級目錄下的某個文件夾,比如「web」文件夾,或者如上圖的「1」文件夾,網站的默認指向目錄又稱為「網站根目錄」,所以你要先確定你的「網站根目錄」是哪一個文件夾。可以咨詢你的空間商,問一下網站的默認指向目錄是什麼。只有確定了網站根目錄,才能知道文件的路徑!

按照你的截圖,當前的目錄可能是頂級目錄,那麼1文件夾可能是網站的根目錄(用數字命名網站的根目錄這種情況非常罕見),當然也不排除當前的頂級目錄就是網站的根目錄。
一、如果1文件夾是根目錄,那麼你的1.txt是無法用通過瀏覽器(網站)訪問的,因為1.txt在根目錄之外;
二、如果當前文件夾是根目錄,那麼直接在瀏覽器中輸入「你的域名地址/1.txt」一般就可以訪問這個文件了。。。

熱點內容
我的世界國際服手機版免費開伺服器 發布:2024-03-28 16:45:36 瀏覽:283
phpmongodb擴展下載 發布:2024-03-28 16:41:03 瀏覽:322
android開發教程筆記 發布:2024-03-28 16:31:48 瀏覽:770
榮威i6max配置怎麼選 發布:2024-03-28 16:18:11 瀏覽:454
cml編程 發布:2024-03-28 16:14:53 瀏覽:757
linuxc語言文件讀寫 發布:2024-03-28 15:59:57 瀏覽:578
點遍歷演算法 發布:2024-03-28 15:57:34 瀏覽:496
java網路框架 發布:2024-03-28 15:42:07 瀏覽:98
我的世界本地部署伺服器 發布:2024-03-28 15:40:55 瀏覽:166
電腦代理伺服器認證 發布:2024-03-28 15:19:17 瀏覽:409