FTP(SSL)下載上傳
代易做图如下:public string[] GetFileList()
{
string[] downloadFiles;
StringBuilder result = new StringBuilder();
FtpWebRequest reqFTP;
try
{
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/"));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
reqFTP.EnableSsl = true;
WebResponse response = reqFTP.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
//MessageBox.Show(reader.ReadToEnd());
string line = reader.ReadLine();
while (line != null)
{
result.Append(line);
result.Append("\n");
line = reader.ReadLine();
}
result.Remove(result.ToString().LastIndexOf('\n'), 1);
reader.Close();
response.Close();
//MessageBox.Show(response.StatusDescription);
return result.ToString().Split('\n');
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
downloadFiles = null;
return downloadFiles;
}
}
運行到: WebResponse response = reqFTP.GetResponse();
報錯:根據驗證程序,遠方憑證時無效的。
小弟第一次寫這樣的東西,從FTP(SSL)上面下載上傳,望高手賜教。或可以提供FTP(SSL)上面下載上傳範例,不甚感激啊!謝謝各位大俠阿!
--------------------编程问答-------------------- WebResponse response = reqFTP.GetResponse();
-------------------------------------------------
WebResponse response = (WebResponse)reqFTP.GetResponse();
--------------------编程问答-------------------- 謝謝,不過還是報相同的錯誤。 --------------------编程问答-------------------- 用 HttpWebRequest 下载的我倒时有
FtpWebRequest 没做过.. --------------------编程问答-------------------- 可以Mail給我參考一下嗎?謝謝!
Mail:woshiyu1@hotmail.com --------------------编程问答-------------------- 主要代码
using System;
using System.Net;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace ServerPort
{
/// <summary>
/// GetHttpSource 的摘要说明。
/// </summary>
public class GetHttpSource
{
public GetHttpSource()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static string GetHttpSourceValue(string a_strUrl)
{
string strResult;
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(new System.Uri(a_strUrl));
myReq.Method = "GET";
myReq.Accept = "*/*";
myReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
try
{
HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
string tmp = myReq.Headers.ToString();
Stream myStream = HttpWResp.GetResponseStream();
StreamReader sr = new StreamReader(myStream, Encoding.Default);
StringBuilder strBuilder = new StringBuilder();
while (-1 != sr.Peek())
{
strBuilder.Append(sr.ReadLine() + "\r\n");
}
strResult = strBuilder.ToString();
// StreamWriter sw = new StreamWriter("E:\\1.txt", false, Encoding.Default);
// sw.Write(strResult);
myStream.Close();
sr.Close();
// sw.Close();
}
catch (Exception exp)
{
strResult = "错误:" + exp.Message;
}
return strResult;
// StreamWriter sw = new StreamWriter(SaveFileName(), false, Encoding.Default);
// sw.Write(body);
// sw.Close();
}
}
} --------------------编程问答-------------------- 帮顶了(真不容易啊,高分贴沉的这么深) --------------------编程问答-------------------- 謝謝,可是看不出來跟ssl的聯繫? --------------------编程问答-------------------- 我已經解決了,謝謝! --------------------编程问答-------------------- 给你一个参考:
http://blog.csdn.net/gisfarmer/archive/2008/09/17/2943126.aspx --------------------编程问答-------------------- 帮你顶下~~ --------------------编程问答-------------------- 楼主能说明下是怎么解决的吗?我也在碰到同样问题。 谢谢 --------------------编程问答-------------------- 我也碰到同一个问题。。求解决 --------------------编程问答-------------------- 这么快就解决了,不错
补充:.NET技术 , C#