|
function:
///<>
///遍历FTP文件
/// </summary>
/// <param name="downloadUrl">要下载的ftp文件路径,如ftp://192.168.1.104/capture-2.avi</param>
/// <param name="saveFileUrl">本地保存文件的路径,如(@"d:\capture-22.avi"</param>
public string[] GetFTPFile(string FTPUrl, string SaveUrl)
{
StreamReader ftpFileListReader = null ;
try
{
string ftpUser = @"Admin";
string ftpPassWord = "Admin123";
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(FTPUrl);
ftpRequest.Credentials = new NetworkCredential(ftpUser, ftpPassWord);
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
ftpRequest.KeepAlive = true;
FtpWebResponse webresp = (FtpWebResponse)ftpRequest.GetResponse();
ftpFileListReader = new StreamReader(webresp.GetResponseStream(), Encoding.Default);
}
catch (Exception ex)
{
string s = ex.Message;
return null;
}
StringBuilder str = new StringBuilder();
string line = ftpFileListReader.ReadLine();
while (line != null)
{
str.Append(line);
string extension = System.IO.Path.GetExtension(FTPUrl + line);//扩展名 “.aspx”
if (extension == "")
{
line = ftpFileListReader.ReadLine();
}
else
{
str.Append("\n");
line = ftpFileListReader.ReadLine();
}
}
string[] fen = str.ToString().Split('\n');
return fen;
}
方法调用:
string sourUrlpath = "ftp://10.90.30.97/usr/local/RAPServer/apache-tomcat/webapps/ddv/png/";
sourUrlpath = "ftp://10.90.30.97/";
string destpath = "D:\\Others\\FTPCopy\\";
string[] GetFIle= GetFTPFile(sourUrlpath,destpath );
问题 :
如果sourUrlpath = "ftp://10.90.30.97/usr/local/RAPServer/apache-tomcat/webapps/ddv/png/";获取FTP响应时系统报错550。。
如果sourUrlpath = "ftp://10.90.30.97/";只能访问linux系统默认路径下的文件。
怎么才能访问指定目录下的文件。。
|
|