使用opencf.net.ftp在c#中为windows mobile 6.5上传/下载ftp

使用opencf.net.ftp在c#中为windows mobile 6.5上传/下载ftp,c#,ftp,compact-framework,windows-mobile-6.5,C#,Ftp,Compact Framework,Windows Mobile 6.5,我试图进行ftp上传和下载,但始终出现Nullreference错误。有可能是opennetcf.net.ftp不是解决问题的最佳方法?有人能帮我解决这个问题吗 命名空间ftp\u加载 { 公共部分类Form1:Form { 公共类FTPManagerClass { 私有静态字符串密码=”; 私有静态字符串username=“”; 私有静态字符串主机=”; 私有FtpWebRequest ftpRequest=null; 私有FtpWebResponse ftpResponse=null; 私有

我试图进行ftp上传和下载,但始终出现
Nullreference
错误。有可能是
opennetcf.net.ftp
不是解决问题的最佳方法?有人能帮我解决这个问题吗

命名空间ftp\u加载
{
公共部分类Form1:Form
{
公共类FTPManagerClass
{
私有静态字符串密码=”;
私有静态字符串username=“”;
私有静态字符串主机=”;
私有FtpWebRequest ftpRequest=null;
私有FtpWebResponse ftpResponse=null;
私有流ftpStream=null;
//私有int bufferSize=2048;
公共FTPManagerClass(字符串用户、字符串传递、字符串主机名)
{
用户名=用户;
密码=通过;
主机=主机名;
}
公共无效下载文件(字符串remoteFile、字符串localFIle)
{
尝试
{
ftpRequest=(FtpWebRequest)FtpWebRequest.Create(主机+“/”+远程文件);
ftpRequest.Credentials=新的网络凭据(用户名、密码);
//ftpRequest.UseBinary=true;
ftpRequest.Method=WebRequestMethods.Ftp.DownloadFile;
ftpResponse=(FtpWebResponse)ftpRequest.GetResponse();
ftpStream=ftpResponse.GetResponseStream();
FileStream fs=newfilestream(localFIle,FileMode.OpenOrCreate);
fs.Close();
ftpStream.Close();
ftpResponse.Close();
ftpRequest=null;
}
捕获(例外情况除外)
{
MessageBox.Show(例如Message);
}
}
公共无效上载文件(字符串localFile、字符串remoteFile)
{
尝试
{
ftpRequest=(FtpWebRequest)FtpWebRequest.Create(主机+“/”+远程文件);
ftpRequest.Credentials=新的网络凭据(用户名、密码);
//ftpRequest.UseBinary=true;
//ftpRequest.UsePassive=true;
ftpRequest.KeepAlive=false;
ftpRequest.Method=WebRequestMethods.Ftp.UploadFile;
ftpStream=ftpRequest.GetRequestStream();
FileStream lfs=newfilestream(localFile,FileMode.Open);
byte[]bytebuffer=新字节[lfs.Length];
int bytesSend=lfs.Read(bytebuffer,0,(int)lfs.Length);
尝试
{
while(bytesSend!=-1)
{
ftpStream.Write(bytebuffer,0,bytesSend);
bytesSend=lfs.Read(bytebuffer,0,(int)lfs.Length);
}
}
捕获(例外情况除外)
{
MessageBox.Show(例如Message);
}
ftpResponse.Close();
ftpStream.Close();
lfs.Close();
ftpRequest=null;
}
捕获(例外情况除外)
{
MessageBox.Show(例如Message);
}
}
}
FTPManagerClass客户端;
私有静态字符串密码=”;
私有静态字符串username=“”;
私有静态字符串主机=”;
私有FtpWebRequest ftpRequest=null;
私有FtpWebResponse ftpResponse=null;
私有流ftpStream=null;
公共表格1()
{
初始化组件();
connMgr=新的connMgr();
connMgr.StatusChanged+=新的connMgr.StatusChangedEventHandler(StatusChanged\U Handler);
}
私人康奈格康奈格;
私有无效按钮1\u单击(对象发送者,事件参数e)
{
如果(txt\u br\u down.Text!=“”)
{
client.DownloadFile(@/GP_FTP/ans.txt),@/download);
客户端=新的FTPManagerClass(“usr”、“pwd”和“ftp://ftp.tzf.com");
}
其他的
{
MessageBox.Show(“Ures mezo”);
}
}
私有void txt\u br\u dw\u 1\u text已更改(对象发送方,事件参数e)
{
}
GPRS连接已建立,但ftp连接后出现一些问题:

private void btn\u登录\u单击(对象发送者,事件参数e)
{
}
私有无效btn\u登录\u单击\u 1(对象发送者,事件参数e)
{
如果(!connMgr.Connected)
{
connMgr.Connect(“pannon”,connMgr.ConnectionMode.Synchronous,”,“”和“net”);
txtLog.Text+=“同步连接成功\r\n”;
}
其他的
{
MessageBox.Show(“无连接!”);
}
}
私有void txtLog_TextChanged(对象发送方,事件参数e)
{
}
私有无效状态更改\u处理程序(对象发送方,ConnMgr.StatusChangedEventArgs e)
{
connMgr.Timeout=3000;
txtLog.Text+=e.desc+“\r\n”;//显示当前状态的描述
如果(!connMgr.正在等待)
如果(连接经理)
txtLog.Text+=“已确认-我们现在已连接\r\n”;
其他的
{
txtLog.Text+=“已确认-已释放连接实例\r\n”;
//btnCancel.Enabled=false;
//btnConnect.Enabled=true;
}
if(e.connstatus==ConnMgr.ConnectionStatus.ExclusiveConflict)
MessageBox.Show(“如果使用活动
client.DownloadFile(@"/GP_FTP/ans.txt", @"/download");
client = new FTPManagerClass("usr", "pwd", "ftp://ftp.tzf.com");
client = new FTPManagerClass("usr", "pwd", "ftp://ftp.tzf.com");
client.DownloadFile(@"/GP_FTP/ans.txt", @"/download");