當前位置:首頁 » 文件傳輸 » go獲取ftp文件
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

go獲取ftp文件

發布時間: 2022-06-25 23:27:22

A. windowsftp如何獲取文件夾下所有的文件

可以通過命令窗口來打開所有的文件。具體步驟如下:
點擊win+R後輸入cmd打開dos命令窗口。
打開需獲取文件名的位置。
獲取名稱,命令格式:dir/b文件目標盤符文件夾位置(可省略)目標名稱.目標後綴。
獲取文件大小及文件名、修改時間(文件大小需處理)。
Microsoft Surface是一個由微軟所開發的第一款平面電腦,結合硬體與軟體的新技術,用家可以直接用手或聲音對屏幕作出指令,觸摸和其他外在物理物來和電腦進行交互,毋須再依賴會令手部勞損的滑鼠與鍵盤。

B. 如何用FTP獲取文件

如果是通過命令行互動式的:
1.
ftp
server_ip
2.
提示輸入用戶名:輸入你的ftp用戶名
3.
提示輸入密碼:輸入ftp用戶的密碼
4.
切換為bin模式:b或者bin命令
5.
用get命令接完整文件名:get
your_file
6.
用wget+通配符模式獲取多個文件:wget
*.txt
7.
退出ftp:bye

C. FTP獲取文件名以及文件路徑

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

D. 如何獲取ftp伺服器下指定文件的大小

//////獲取ftp伺服器上指定文件夾的文件列表(包含文件大小)//////////////////publicDictionaryGetFTPList(stringServerIP,stringUSERID,stringPassWord,stringpath){Dictionarydic=newDictionary();if(path==null)path="";FtpWebRequestreqFtp;try{reqFtp=(FtpWebRequest)FtpWebRequest.Create(newUri("ftp://"+ServerIP+"/"+path));reqFtp.KeepAlive=false;reqFtp.UseBinary=true;//指定ftp數據傳輸類型為二進制reqFtp.Credentials=newNetworkCredential(USERID,PassWord);//設置於ftp通訊的憑據reqFtp.Method=WebRequestMethods.Ftp.ListDirectoryDetails;//指定操作方式WebResponseresponse=reqFtp.GetResponse();//獲取一個FTP響應StreamReaderreader=newStreamReader(response.GetResponseStream(),Encoding.GetEncoding("GB2312"));//讀取響應流stringline=reader.ReadLine();while(line!=null){if(line!="."&&line!=".."){intend=line.LastIndexOf('');intstart=line.IndexOf("");stringfilename=line.Substring(end+1);if(filename.Contains(".")){line=line.Replace(filename,"");dic.Add(filename.Trim(),int.Parse(line.Substring(start).Trim()));}}line=reader.ReadLine();}}catch(Exceptionex){Console.WriteLine(ex.Message);}returndic;}文件夾或者某一文件都適用

E. Linux下如何獲取FTP文件名和大小

path='' #這里的$1,換成你需要的路徑名,或者你不換,通過shell的參數傳入
for dirlist in $(find ${path} -name *.xml)
do
echo ${dirlist}
查找,刪除,比較都在這做
done

F. 怎麼用ftp 取文件 命令

熟悉並靈應用FTP內部命令便使用者並收事半功倍效
FTP命令行格式:ftp -v -d -i -n -g [主機名]其
-v顯示遠程伺服器所響應信息;
-n限制ftp自登錄即使用;
.n etrc文件;
-d使用調試式;
-g取消全局文件名
ftp使用內部命令(括弧表示選項):
1.![cmd[args]]:本機執行交互shellexitftp環境:!ls*.zip.
2.$ macro-ame[args]:執行宏定義macro-name.
3.account[password]:提供登錄遠程系統功訪問系統資源所需補充口令
4.append local-file[remote-file]:本文件追加遠程系統主機若未指定遠程系統文件名則使用本文件名
5.ascii:使用ascii類型傳輸式
6.bell:每命令執行完畢計算機響鈴
7.bin:使用二進制文件傳輸式
8.bye:退ftp程
9.case:使用mget遠程主機文件名寫轉寫字母
10.cd remote-dir:進入遠程主機目錄
11.cp:進入遠程主機目錄父目錄
12.chmod mode file-name:遠程主機文件file-name存取式設置mode:chmod 777 a.out
13.close:斷與遠程伺服器ftp(與open應)
14.cr:使用asscii式傳輸文件車換行轉換行

G. java獲取ftp文件路徑怎麼寫

package com.weixin.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.RandomAccessFile;

import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;

import com.weixin.constant.DownloadStatus;
import com.weixin.constant.UploadStatus;

/**
* 支持斷點續傳的FTP實用類
* @version 0.1 實現基本斷點上傳下載
* @version 0.2 實現上傳下載進度匯報
* @version 0.3 實現中文目錄創建及中文文件創建,添加對於中文的支持
*/
public class ContinueFTP {
public FTPClient ftpClient = new FTPClient();

public ContinueFTP(){
//設置將過程中使用到的命令輸出到控制台
this.ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
}

/**
* 連接到FTP伺服器
* @param hostname 主機名
* @param port 埠
* @param username 用戶名
* @param password 密碼
* @return 是否連接成功
* @throws IOException
*/
public boolean connect(String hostname,int port,String username,String password) throws IOException{
ftpClient.connect(hostname, port);
ftpClient.setControlEncoding("GBK");
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("GBK"),"iso-8859-1"));
if(files.length != 1){
System.out.println("遠程文件不存在");
return DownloadStatus.Remote_File_Noexist;
}

long lRemoteSize = files[0].getSize();
File f = new File(local);
//本地存在文件,進行斷點下載
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("GBK"),"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("GBK"),"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;
}

/**
* 上傳文件到FTP伺服器,支持斷點續傳
* @param local 本地文件名稱,絕對路徑
* @param remote 遠程文件路徑,使用/home/directory1/subdirectory/file.ext 按照Linux上的路徑指定方式,支持多級目錄嵌套,支持遞歸創建不存在的目錄結構
* @return 上傳結果
* @throws IOException
*/
public UploadStatus upload(String local,String remote) throws IOException{
//設置PassiveMode傳輸
ftpClient.enterLocalPassiveMode();
//設置以二進制流的方式傳輸
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.setControlEncoding("GBK");
UploadStatus result;
//對遠程目錄的處理
String remoteFileName = remote;
if(remote.contains("/")){
remoteFileName = remote.substring(remote.lastIndexOf("/")+1);
//創建伺服器遠程目錄結構,創建失敗直接返回
if(CreateDirecroty(remote, ftpClient)==UploadStatus.Create_Directory_Fail){
return UploadStatus.Create_Directory_Fail;
}
}

//檢查遠程是否存在文件
FTPFile[] files = ftpClient.listFiles(new String(remoteFileName.getBytes("GBK"),"iso-8859-1"));
if(files.length == 1){
long remoteSize = files[0].getSize();
File f = new File(local);
long localSize = f.length();
if(remoteSize==localSize){
return UploadStatus.File_Exits;
}else if(remoteSize > localSize){
return UploadStatus.Remote_Bigger_Local;
}

//嘗試移動文件內讀取指針,實現斷點續傳
result = uploadFile(remoteFileName, f, ftpClient, remoteSize);

//如果斷點續傳沒有成功,則刪除伺服器上文件,重新上傳
if(result == UploadStatus.Upload_From_Break_Failed){
if(!ftpClient.deleteFile(remoteFileName)){
return UploadStatus.Delete_Remote_Faild;
}
result = uploadFile(remoteFileName, f, ftpClient, 0);
}
}else {
result = uploadFile(remoteFileName, new File(local), ftpClient, 0);
}
return result;
}
/**
* 斷開與遠程伺服器的連接
* @throws IOException
*/
public void disconnect() throws IOException{
if(ftpClient.isConnected()){
ftpClient.disconnect();
}
}

/**
* 遞歸創建遠程伺服器目錄
* @param remote 遠程伺服器文件絕對路徑
* @param ftpClient FTPClient對象
* @return 目錄創建是否成功
* @throws IOException
*/
public UploadStatus CreateDirecroty(String remote,FTPClient ftpClient) throws IOException{
UploadStatus status = UploadStatus.Create_Directory_Success;
String directory = remote.substring(0,remote.lastIndexOf("/")+1);
if(!directory.equalsIgnoreCase("/")&&!ftpClient.changeWorkingDirectory(new String(directory.getBytes("GBK"),"iso-8859-1"))){
//如果遠程目錄不存在,則遞歸創建遠程伺服器目錄
int start=0;
int end = 0;
if(directory.startsWith("/")){
start = 1;
}else{
start = 0;
}
end = directory.indexOf("/",start);
while(true){
String subDirectory = new String(remote.substring(start,end).getBytes("GBK"),"iso-8859-1");
if(!ftpClient.changeWorkingDirectory(subDirectory)){
if(ftpClient.makeDirectory(subDirectory)){
ftpClient.changeWorkingDirectory(subDirectory);
}else {
System.out.println("創建目錄失敗");
return UploadStatus.Create_Directory_Fail;
}
}

start = end + 1;
end = directory.indexOf("/",start);

//檢查所有目錄是否創建完畢
if(end <= start){
break;
}
}
}
return status;
}

/**
* 上傳文件到伺服器,新上傳和斷點續傳
* @param remoteFile 遠程文件名,在上傳之前已經將伺服器工作目錄做了改變
* @param localFile 本地文件File句柄,絕對路徑
* @param processStep 需要顯示的處理進度步進值
* @param ftpClient FTPClient引用
* @return
* @throws IOException
*/
public UploadStatus uploadFile(String remoteFile,File localFile,FTPClient ftpClient,long remoteSize) throws IOException{
UploadStatus status;
//顯示進度的上傳
long step = localFile.length() / 100;
long process = 0;
long localreadbytes = 0L;
RandomAccessFile raf = new RandomAccessFile(localFile,"r");
OutputStream out = ftpClient.appendFileStream(new String(remoteFile.getBytes("GBK"),"iso-8859-1"));
//斷點續傳
if(remoteSize>0){
ftpClient.setRestartOffset(remoteSize);
process = remoteSize /step;
raf.seek(remoteSize);
localreadbytes = remoteSize;
}
byte[] bytes = new byte[1024];
int c;
while((c = raf.read(bytes))!= -1){
out.write(bytes,0,c);
localreadbytes+=c;
if(localreadbytes / step != process){
process = localreadbytes / step;
System.out.println("上傳進度:" + process);
//TODO 匯報上傳狀態
}
}
out.flush();
raf.close();
out.close();
boolean result =ftpClient.completePendingCommand();
if(remoteSize > 0){
status = result?UploadStatus.Upload_From_Break_Success:UploadStatus.Upload_From_Break_Failed;
}else {
status = result?UploadStatus.Upload_New_File_Success:UploadStatus.Upload_New_File_Failed;
}
return status;
}

public static void main(String[] args) {
ContinueFTP myFtp = new ContinueFTP();
try {
System.err.println(myFtp.connect("10.10.6.236", 21, "5", "jieyan"));
// myFtp.ftpClient.makeDirectory(new String("歌曲".getBytes("GBK"),"iso-8859-1"));
// myFtp.ftpClient.changeWorkingDirectory(new String("歌曲".getBytes("GBK"),"iso-8859-1"));
// myFtp.ftpClient.makeDirectory(new String("愛你等於愛自己".getBytes("GBK"),"iso-8859-1"));
// System.out.println(myFtp.upload("E:\\yw.flv", "/yw.flv",5));
// System.out.println(myFtp.upload("E:\\愛你等於愛自己.mp4","/愛你等於愛自己.mp4"));
//System.out.println(myFtp.download("/愛你等於愛自己.mp4", "E:\\愛你等於愛自己.mp4"));
myFtp.disconnect();
} catch (IOException e) {
System.out.println("連接FTP出錯:"+e.getMessage());
}
}
}

H. 用JAVA獲取FTP文件列表

學習一下ftp協議,然後用socket來模擬就可以了

I. 如何訪問ftp站點並獲取資料

間接下載資源工具:FlashFXP v3.40 多國語言版 http://www.crsky.com/soft/1183.html
迅雷5 的 ftp探測器 http://down.sandai.net:8080/Thunder5.1.3.168.exe
flashget (網際快車) http://www.onlinedown.net/soft/15.htm
cuteftp http://down.crsky.com/DL/cuteftp71-chs.rar
以上均是很好的ftp下載工具

直接訪問下載方法:在地址欄中,鍵入要連接的 FTP 站點的 Internet 地址 (URL)。例如:ftp://ftp.microsoft..com/
要下載文件或文件夾,請用右鍵單擊 Web 頁中的項目,然後單擊「下載到」。
要以其他用戶身份登錄到此 FTP 站點,請單擊「文件」菜單,然後單擊「登錄」。

要重命名或刪除 FTP 文件夾中的項目或將項目粘貼到 FTP 站點(上載),可以使用與「Windows 資源管理器」或「我的電腦」相同的命令和操作。

注意

在部分 FTP 站點上,只能查看或下載文件。只有運行或擁有站點的人才能重命名、刪除或上載文件。
在許多 FTP 站點上,您都可以自動匿名登錄,從而查看或下載文件。要上載、重命名或刪除文件,可能需要使用特殊的用戶名和密碼登錄。同時,相同站點的不同區域也可能需要進行不同的登錄。
文件不能在 FTP 站點內部和站點之間移動。您可以從 FTP 站點將文件移動到您的計算機或網路驅動器上的臨時位置,然後再將它們上載到另一個 FTP 站點或相同站點的其他文件夾中。
部分程序允許在「文件打開」或「文件保存」對話框中鍵入 FTP 地址,從而打開和保存 FTP 伺服器上的