[問題] 使用MOBILE寫FTP上傳程式一問

看板C_Sharp作者 (123)時間14年前 (2010/06/03 01:36), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
最近在寫一個MOBILE的FTP上傳程式 程式碼如下 FtpWebRequest ftpRequest; FtpWebResponse ftpResponse; //string fileName = Path.GetFileName(filePath); string fileName = "test.wav"; FileInfo oFile = new FileInfo(fileName); try { FtpRequestCreator creator = new FtpRequestCreator(); WebRequest.RegisterPrefix("ftp:", creator); // Building our URI object Uri testUri; if ("192.168.0.189".IndexOf("ftp:") != 0) { testUri = new Uri("ftp:"); } else testUri = new Uri("ftp://); //Settings required to establish a connection with //the server MessageBox.Show(testUri + oFile.Name, "create"); ftpRequest = (FtpWebRequest)FtpWebRequest. Create(testUri + oFile.Name); ftpRequest.Method = OpenNETCF.Net.WebRequestMethods.Ftp.UploadFile; ftpRequest.Proxy = null; //ftpRequest.UseBinary = true; ftpRequest.Credentials = new NetworkCredential("anonymous", "user"); //Selection of file to be uploaded byte[] fileContents = new byte[oFile.Length]; MessageBox.Show(oFile.Length.ToString(), "lenght"); //will destroy the object immediately after being used using (FileStream fr = oFile.OpenRead()) { fr.Read(fileContents, 0, Convert.ToInt32(oFile.Length)); } using (Stream writer = ftpRequest.GetRequestStream()) { writer.Write(fileContents, 0, fileContents.Length); }} finally{ ftpRequest = null; } } 最後都會出現以下的錯誤 不知道是哪邊出了問題 請求各位大大幫忙 System.ArgumentException 未處理 Message="值未落在預期的範圍內。" StackTrace: 於 System.Enum.ToObject() 於 OpenNETCF.Net.Ftp.FtpWebRequest.set_Method() 於 DeviceApplication6.Form1.button3_Click() 於 System.Windows.Forms.Control.OnClick() 於 System.Windows.Forms.Button.OnClick() 於 System.Windows.Forms.ButtonBase.WnProc() 於 System.Windows.Forms.Control._InternalWnProc() 於 Microsoft.AGL.Forms.EVL.EnterMainLoop() 於 System.Windows.Forms.Application.Run() 於 DeviceApplication6.Program.Main() 謝謝大家了 ORZ!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.44.202.134 ※ 編輯: ist123 來自: 114.44.202.134 (06/03 01:48)
文章代碼(AID): #1C1fQHIS (C_Sharp)