【问题标题】:how to retrieve list of pdf files from ftp server's folder and shown it as .pdf link in aspx page?如何从 ftp 服务器的文件夹中检索 pdf 文件列表并将其显示为 aspx 页面中的 .pdf 链接?
【发布时间】:2013-08-20 10:16:14
【问题描述】:

我正在使用一个文件上传控制器,它通过在其上创建一个文件夹将 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();
   }`

【问题讨论】:

    标签: c# asp.net ftp


    【解决方案1】:

    列表命令来拯救!

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

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

    【讨论】:

      猜你喜欢
      • 2013-10-14
      • 2011-01-19
      • 1970-01-01
      • 1970-01-01
      • 2013-11-03
      • 2013-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多