我想將多行文本框流式傳輸到FTP服務器上的文本文件中。有人能告訴我我哪裏可能會出問題嗎?將文本框上傳到ftp C上的文本文件#
private void btnSave_Click(object sender, EventArgs e)
{
UriBuilder b = new UriBuilder();
b.Host = "ftp.myserver.com";
b.UserName = "user";
b.Password = "pass";
b.Port = 21;
b.Path = "/myserver.com/directories/" + selected + ".txt";
b.Scheme = Uri.UriSchemeFtp;
Uri g = b.Uri;
System.Net.FtpWebRequest c = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(g);
c.Method = System.Net.WebRequestMethods.Ftp.DownloadFile;
System.Net.FtpWebResponse d = (System.Net.FtpWebResponse)c.GetResponse();
System.IO.Stream h = d.GetResponseStream;
System.IO.StreamWriter SW = new System.IO.StreamWriter(h);
String[] contents = textBox1.Lines.ToArray();
for (int i = 0; i < contents.Length; i++)
{
SW.WriteLine(contents[i]);
}
h.Close();
SW.Close();
d.Close();
}
我正的錯誤是這樣的線:
System.IO.StreamWriter SW =新System.IO.StreamWriter(H);
流不可寫。
任何想法?
當我切換到上傳文件I得到這一行一個錯誤: System.IO.Stream H = d.GetResponseStream; 無法將方法組「GetResponseStream」轉換爲非委託類型「System.IO.Stream」。你打算採用這種方法嗎? – David 2010-01-22 16:38:09
我現在得到這行的錯誤:System.IO.StreamWriter SW = new System.IO.StreamWriter(h);流不可寫... – David 2010-01-22 16:45:33
正如我在答案中所說的,你不應該打開響應流 - 你應該打開* request *流。 – 2010-01-22 17:03:42