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

ftp只讀取當天文件列表

發布時間: 2022-06-17 22:44:27

A. 求一段可以讀取FTP一個文件夾下面當天更新數據的文件 ,c#寫的代碼

#region 下載文件

/**//// <summary>
/// 從FTP伺服器下載文件,使用與遠程文件同名的文件名來保存文件
/// </summary>
/// <param name="RemoteFileName">遠程文件名</param>
/// <param name="LocalPath">本地路徑</param>

public bool DownloadFile(string RemoteFileName, string LocalPath)
{
return DownloadFile(RemoteFileName, LocalPath, RemoteFileName);
}
/**//// <summary>
/// 從FTP伺服器下載文件,指定本地路徑和本地文件名
/// </summary>
/// <param name="RemoteFileName">遠程文件名</param>
/// <param name="LocalPath">本地路徑</param>
/// <param name="LocalFilePath">保存文件的本地路徑,後面帶有"\"</param>
/// <param name="LocalFileName">保存本地的文件名</param>
public bool DownloadFile(string RemoteFileName, string LocalPath, string LocalFileName)
{
byte[] bt = null;
try
{
if (!IsValidFileChars(RemoteFileName) || !IsValidFileChars(LocalFileName) || !IsValidPathChars(LocalPath))
{
throw new Exception("非法文件名或目錄名!");
}
if (!Directory.Exists(LocalPath))
{
throw new Exception("本地文件路徑不存在!");
}

string LocalFullPath = Path.Combine(LocalPath, LocalFileName);
if (File.Exists(LocalFullPath))
{
throw new Exception("當前路徑下已經存在同名文件!");
}
bt = DownloadFile(RemoteFileName);
if (bt != null)
{
FileStream stream = new FileStream(LocalFullPath, FileMode.Create);
stream.Write(bt, 0, bt.Length);
stream.Flush();
stream.Close();
return true;
}
else
{
return false;
}
}
catch (Exception ep)
{
ErrorMsg = ep.ToString();
throw ep;
}
}

/**//// <summary>
/// 從FTP伺服器下載文件,返迴文件二進制數據
/// </summary>
/// <param name="RemoteFileName">遠程文件名</param>
public byte[] DownloadFile(string RemoteFileName)
{
try
{
if (!IsValidFileChars(RemoteFileName))
{
throw new Exception("非法文件名或目錄名!");
}
Response = Open(new Uri(this.Uri.ToString() + RemoteFileName), WebRequestMethods.Ftp.DownloadFile);
Stream Reader = Response.GetResponseStream();

MemoryStream mem = new MemoryStream(1024 * 500);
byte[] buffer = new byte[1024];
int bytesRead = 0;
int TotalByteRead = 0;
while (true)
{
bytesRead = Reader.Read(buffer, 0, buffer.Length);
TotalByteRead += bytesRead;
if (bytesRead == 0)
break;
mem.Write(buffer, 0, bytesRead);
}
if (mem.Length > 0)
{
return mem.ToArray();
}
else
{
return null;
}
}
catch (Exception ep)
{
ErrorMsg = ep.ToString();
throw ep;
}
}
#endregion

B. 如何使用批處理從FTP伺服器上下載當天創建的所有文件

FTP命令好象不能那麼篩選,不過你可以在DATE下建立一個新文件夾,把所有文件都放進去,然後DATE下就只有每天創建的文件文件,下載下來後在移動過去,這樣不就簡單了
然後你可以每天用下面的腳本來下載文件
@echo
off
echo
open
192.168.1.1
>
"%userprofile%\Local
Settings\Temp\ftpin"
echo
user
>>
"%userprofile%\Local
Settings\Temp\ftpin"
echo
user
>>
"%userprofile%\Local
Settings\Temp\ftpin"
echo
cd
date
>>
"%userprofile%\Local
Settings\Temp\ftpin"
echo
binary
>>
"%userprofile%\Local
Settings\Temp\ftpin"
echo
mget
*.*
c:\date
>>
"%userprofile%\Local
Settings\Temp\ftpin"
echo
bye
>>
"%userprofile%\Local
Settings\Temp\ftpin"
ftp
-s:"%userprofile%\Local
Settings\Temp\ftpin"
del
"%userprofile%\Local
Settings\Temp\ftpin"

C. 在FTP命令當中查看本地文件列表命令是

查看本地文件列表命令是:ls

其它常用的FTP命令及含義:

1、dir:顯示伺服器目錄和文件列表

2、cd:進入伺服器指定的目錄(dir命令可以使用通配符「」和「?」,比如,顯示當前目錄中所有擴展名為jpg的文件,可使用命令 dir .jpg。)

3、put:上傳指定文件put filename [newname]

4、、send:上傳指定文件send filename [newname]

(filename為上傳的本地文件名,newname為上傳至FTP伺服器上時使用的名字,如果不指定newname,文件將以原名上傳。)

(3)ftp只讀取當天文件列表擴展閱讀

ftp命令行格式及開關含義:

ftp [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-w:windowsize] [computer]

-v - 禁止顯示遠程伺服器相應信息

-n - 禁止自動登錄

-i - 多文件傳輸過程中關閉交互提示

-d - 啟用調試,顯示所有客戶端與伺服器端傳遞的命令

-g - 禁用文件名通配符,允許在本地文件和路徑名中使用

-s:filename - 指定包含 FTP 命令的文本文件;命令在FTP啟動後自動運行。此參數中沒有空格。可替代重定向符(>)使用。

-a - 在綁字數據連接時使用所有本地介面

-w:windowsize - 覆蓋默認的傳輸緩沖區大小 65535。

computer - 指定遠程電腦計算機名或IP地址。此參數必須放到最後。

D. ftp目錄設置為只讀(設置後該目錄無法更改,刪除,添加文件,只允許讀取。),對SEO有影響嗎

不會有影響的,只讀只是對用戶操作來說有影響,對搜索引擎抓取是沒有任何影響的。

E. 搭建的FTP伺服器,匿名用戶只能查看文件列表,卻無開打開文檔和文件夾

你是用微軟的IIS服務中的FTP嗎?建議你用serverU。
你測試你的FTP服務時,移動文件夾是需要建立和刪除許可權的,你賦予你的匿名用戶了嗎?另外
記得刷新你的瀏覽器。多嘗試是最好的老師。相信你會搭建成的!不只是匿名用戶包括授權用戶。

F. FTP怎麼讀取一個特定目錄文件

樓主您好,您可以把ftp用戶的家目錄設置為你需要讀取的目錄,然後不然其跳出自己的家目錄。這樣您一連接ftp就進入您需要讀取的目錄了。

G. C# 獲取Ftp某個目錄下的所有文件(不要文件夾)

我在之前做過一個FTP的客戶端工具。
drw 文件夾
-rw 文件(有擴展名或無擴展名)
我是根據服務端返回的報文進行分析獲取的列表。
給你一些代碼片段:
/// <summary>
/// 獲取指定目錄下的文件和文件夾。
/// </summary>
/// <param name="path">要獲取的目錄</param>
/// <param name="WRMethods">要發送到FTP伺服器的密令。</param>
/// <returns></returns>
public string[] GetFileList(string path, string WRMethods)//從ftp伺服器上獲得文件列表
{
WebResponse response;
string[] downloadFiles;
int conut = 4;
StringBuilder result = new StringBuilder();
Connect(path);
if (FTPVariable.IsUseProxy_ftp)
{
reqFTP.Proxy = FtpProxy.GetFtpSelectProxy(FTPVariable.FtpCommand_transferProxyName);
}
reqFTP.ReadWriteTimeout = 12000;
//如果不應銷毀到伺服器的連接,則為 true;否則為 false。默認值為 true。
//
reqFTP.Method = WRMethods;
try
{
response = (FtpWebResponse)reqFTP.GetResponse();
goto Ftp_lbl_03;
}
catch (WebException webex)
{
GetReply(webex.Message);
if (ReplyCode == 530)// 未登錄。
{
goto Ftp_lbl_04;
}
else if (ReplyCode == 550)
{
goto Ftp_lbl_04;
}
else
{
FtpManage.SetLog("獲取列表超時,等候1秒後重試!");
goto Ftp_lbl_01;
}
}
Ftp_lbl_01:
try
{
FtpManage.SetLog("正在連接伺服器 " + FtpRemoteHost);
response = GetRequest(path, WRMethods);
}
catch (WebException)
{
FtpManage.SetLog("獲取列表超時,等候1秒後重試!");
downloadFiles = null;
System.Threading.Thread.Sleep(1000);
if (conut == 0)
{
goto Ftp_lbl_02;
}
conut--;
goto Ftp_lbl_01;
}
catch (Exception ex)
{
MSG.Show(ex.Message, Global.GetRS["msgTilteError"], MessageBoxButton.OK, MsgIco.Error);
FtpManage.SetLog("命令執行失敗,原因:" + ex.Message);
downloadFiles = null;
return downloadFiles;
}
Ftp_lbl_03:
StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);//中文文件名
string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
if (result.Length == 0)
{
return null;
}
// to remove the trailing '\n'
result.Remove(result.ToString().LastIndexOf('\n'), 1);
reader.Close();
response.Close();
FtpManage.SetLog("命令已成功執行");
return result.ToString().Split('\n');
Ftp_lbl_04:
FtpManage.SetLog(ReplyInfo);
return null;
Ftp_lbl_02:
FtpManage.SetLog("550 獲取列表失敗,無法連接遠程伺服器!");
FtpManage.ftpmanage.IsRefurbish = true;
return null;
}
/// <summary>
/// 獲取指定目錄下的文件和文件夾。
/// </summary>
/// <param name="path">要獲取的目錄</param>
/// <returns></returns>
public string[] GetFileList(string path)//從ftp伺服器上獲得文件列表
{
return GetFileList(FTPVariable.FtpURLhead + FtpRemoteHost + "/" + path, WebRequestMethods.Ftp.ListDirectory);
}

/// <summary>
/// 獲取指定目錄下的文件和文件夾。
/// </summary>
/// <returns></returns>
public string[] GetFileList()//從ftp伺服器上獲得文件列表
{
return GetFileList(FTPVariable.FtpURLhead + FtpRemoteHost + "/", WebRequestMethods.Ftp.ListDirectory);
}

/// <summary>
/// 獲取目錄和文件名,返回目錄表。
/// </summary>
/// <param name="path">要獲取的目錄</param>
/// <returns></returns>
public string[] GetCatalog_FileList(string path)
{
string[] fountainhead = GetFileList(FTPVariable.FtpURLhead + FtpRemoteHost + "/" + path, WebRequestMethods.Ftp.ListDirectoryDetails);
string[] Catalog = null;
if (fountainhead == null)
{
return null;
}
Catalog = new string[fountainhead.Length];
for (int i = 3; i < fountainhead.Length; i++)
{
Catalog[i - 3] += fountainhead[i].Substring(55, fountainhead[i].Length - 55) + "&";//FileName
Catalog[i - 3] += fountainhead[i].Substring(30, 12) + "&";//FileSize
Catalog[i - 3] += fountainhead[i].Substring(42, 13) + "&";//AmendDate
Catalog[i - 3] += fountainhead[i].Substring(0, 3) + "&";
}
return Catalog;
}

H. 用JAVA獲取FTP文件列表

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

I. 如何使用批處理從FTP伺服器上下載當天創建的所有文件夾

ftp>
open
123.123.123.123
ftp>
connected
to
接下來伺服器詢問你用戶名和口令
ftp>
cd
wwwroot
ftp>
get
123
也可以在ie地址欄輸入ftp地址,輸入賬號和密碼,然後就可以訪問

J. java如何獲取ftp制定目錄下所有文件集合(包括文件名稱)只要一個方法。

/**
* 取得相對於當前連接目錄的某個目錄下所有文件列表
*
* @param path
* @return
*/
public List getFileList(String path){
List list = new ArrayList();
DataInputStream dis;
try {
dis = new DataInputStream(ftpClient.nameList(this.path + path));
String filename = "";
while((filename = dis.readLine()) != null){
list.add(filename);
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
我從這里拷來的 你不清楚看看裡面 http://hi..com/yuanhotel/item/000b6334894d11f42784f4da
滿意就採納 謝謝