繁体   English   中英

如何从ftp服务器的文件夹中检索pdf文件列表,并在aspx页中将其显示为.pdf链接?

[英]how to retrieve list of pdf files from ftp server's folder and shown it as .pdf link in aspx page?

我正在使用文件上传控制器,通过在其上创建文件夹将pdf文件上传到ftp服务器。 现在,我需要在文件上传控制器下方显示此上传的pdf文件作为链接。 这怎么可能? 如何从ftp服务器上的特定文件夹中读取所有pdf文件? 每个pdf文件具有不同的名称格式。 我上传文件的代码在这里

protected void UploadButton_Click(object sender, EventArgs e)
{


      bool is_folder_exists= FtpDirectoryExists("ftp://xxx.co//"+test_id+"/"+student_id+"", userName, password);
if (is_folder_exists == true)
   {
  MessageBox.Show("Folder" + is_folder_exists);
  string filename = Path.GetFileName(FileUpload1.FileName);

  System.Net.FtpWebRequest rq = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create("ftp://xxx.co/" + test_id + "/" + student_id + "/" + filename + "");
  rq.Credentials = new System.Net.NetworkCredential("cccc", "xxx");
  rq.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
  System.IO.Stream fs = FileUpload1.PostedFile.InputStream;
  byte[] buffer = new byte[fs.Length];
  fs.Read(buffer, 0, buffer.Length);
  fs.Close();
  System.IO.Stream ftpstream = rq.GetRequestStream();
  ftpstream.Write(buffer, 0, buffer.Length);
  ftpstream.Close();
   }`

list命令可以解救!

cd:更改远程计算机上的目录。 ls:列出当前远程目录中文件的名称。

http://www.cs.colostate.edu/helpdocs/ftp.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM