I'm having problems translating some code for FTP transfer from WinForm to Windows-CE C#.
I have this code for transfer from a local computer to an FTP server. It's working excellent on WinForm, I must have this on Windows-CE and it doesn't work. The code:
string MyFile = @"d:\PC.sdf";
string url = "ftp://127.0.0.1/PC.sdf";
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(url);
request.Method = WebRequestMethods.Ftp.UploadFile;
// request.Credentials = new NetworkCredential("user name", "password");
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
// byte[] buffer = Fil开发者_开发技巧e.ReadAllBytes(MyFile);
using (Stream reqStream = request.GetRequestStream())
{
int count = 0;
byte[] buffer = new byte[100];
using (FileStream file = new FileStream(MyFile, FileMode.Open))
{
while ((count = file.Read(buffer, 0, 100)) > 0)
{
reqStream.Write(buffer, 0, count);
}
}
}
Be more specific, "it does not work" wont get you very far on SO. As a start, I think the FTPWebRequest is not supported on WinCE, see here
精彩评论