簡體   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