我有使用FTP,即時通訊上傳在C# 的方式即時通訊做它不工作 我得到一個錯誤,說流關閉3演出XML文件.. 。
和0字節的文件,當我做一個小flie它的工作原理... 我需要幫助:)如何上傳使用FTP 3gig XML文件在C#中
m_reset.Reset();
FtpClient conn = new FtpClient();
_LocalPath = LocalFilePath;
conn.Host = record.Attribute("ftpServer").Value.ToString();
conn.Credentials = new NetworkCredential(record.Attribute("ftpUser").Value.ToString(), record.Attribute("ftpPass").Value.ToString());
string fname = DateTime.Now.ToString("EnvisionPush-{0:yyyy-MM-dd_hh_mm_ss_tt}"+".xml");
conn.BeginOpenWrite(fname, new AsyncCallback(BeginOpenWriteCallback), conn);
m_reset.WaitOne();
conn.Disconnect();
static void BeginOpenWriteCallback(IAsyncResult ar) {
FtpClient conn = ar.AsyncState as FtpClient;
Stream istream = null, ostream = null;
byte[] buf = new byte[8192];
int read = 0;
try {
if (conn == null)
throw new InvalidOperationException("The FtpControlConnection object is null!");
ostream = conn.EndOpenWrite(ar);
istream = new FileStream(_LocalPath, FileMode.Open, FileAccess.Read);
while ((read = istream.Read(buf, 0, buf.Length)) > 0) {
ostream.Write(buf, 0, read);
}
}
catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
finally {
try {
if (istream != null)
istream.Close();
if (ostream != null)
ostream.Close();
m_reset.Set();
}
catch (Exception e) {
}
}
}
Hav you any error? –
是的錯誤是一個流關閉錯誤 – Rico