作者ist123 (123)
看板C_Sharp
标题[问题] 使用MOBILE写FTP上传程式一问
时间Thu Jun 3 01:36:15 2010
最近在写一个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)