vfp messageboxx(p[0][0] ...

本博推荐文章快速导航:
.net,Flex,Fms,视频会议,视频聊天相关开发技术大本营
相关文章导航
最近项目需要对FTP服务器进行操作,现把实现总结如下:打算分2篇总结:
Microsoft .NET Framework 2.0新增加了3个类使我们很方便的对文件传输协议(FTP)服务器进行操作FtpWebRequest类:实现文件传输协议(FTP)客户端public sealed class FtpWebRequest : WebRequest
FtpWebResponse类:封装文件传输协议(FTP)服务器对请求的响应 public class FtpWebResponse : WebResponse, IDisposable
WebRequestMethods.Ftp类:表示可与FTP请求一起使用的FTP协议方法的类型,无法继承此类 public static class Ftp
操作ftp的一般步骤我总结如下:第一步:WebRequest.Create方法,获得FtpWebRequest的实例第二步:利用WebRequestMethods.Ftp设置FtpWebRequest的Method属性,指定使用的FTP协议方法的类型第三步:设置FtpWebRequest的Credentials属性,指定用户名和密码第四步:发出请求第五步:接收响应数据流(有些ftp操作可能没这一步,例如给文件夹改名)第六步:关闭流
下面从几段代码来分别展示ftp的不同操作:1.文件夹和文件信息关键知识说明:a.FtpWebRequest类没有公开的构造函数,我们通过WebRequest.Create方法,获得FtpWebRequest的实例b.通过WebRequestMethods.Ftp.ListDirectoryDetails(详细列表)或者WebRequestMethods.Ftp.ListDirectory(简短列表)获取FTP服务器上的文件列表c.请求返回的数据在GetResponseStream方法返回的流中d.字符编码请用System.Text.Encoding.Default,要不中文名会乱码e.FtpWebRequest.Credentials属性设置登陆用户名和密码f.FtpWebRequest.UseBinary属性,true,指示服务器要传输的是二进制数据.false,指示数据为文本。默认值为trueg.FtpWebRequest.EnableSsl属性,如果控制和数据传输是加密的,则为true.否则为false.默认值为 false
实例代码:获取上的文件信息Uri uri = new Uri ( "" );
FtpWebRequest listRequest = ( FtpWebRequest ) WebRequest.Create ( uri );
listRequest.Method = WebRequestMethods.Ftp.ListDirectoryD//listRequest.Method = WebRequestMethods.Ftp.ListD
string ftpUser = "";string ftpPassWord = "";listRequest.Credentials = new NetworkCredential ( ftpUser , ftpPassWord );
FtpWebResponse listResponse = ( FtpWebResponse ) listRequest.GetResponse ( );Stream responseStream = listResponse.GetResponseStream ( );StreamReader readStream = new StreamReader ( responseStream , System.Text.Encoding.Default );
if ( readStream != null ){&&& MessageBox.Show ( readStream.ReadToEnd ( )& );}
MessageBox.Show ( string.Format ( "状态: {0},{1}" ,listResponse.StatusCode,& listResponse.StatusDescription ) );
listResponse.Close ( );responseStream.Close ( );readStream.Close ( );
通过WebRequestMethods.Ftp.ListDirectoryDetails(详细列表)或者WebRequestMethods.Ftp.ListDirectory(简短列表)返回的结果是不一样的.请看图
利用WebRequestMethods.Ftp.ListDirectoryDetails,readStream.ReadToEnd ( )返回的字符串比较复杂(不同类型的Ftp会有不同返回形式的返回结果),要把里面的文件夹和文件区分别列出来比较繁琐,代码比较多.大概的调用方法如下:string dataString = readStream.ReadToEnd ( );DirectoryListParser parser = new DirectoryListParser ( dataString );FileStruct [ ] fs = parser.FullL返回的FileStruct有一个属性IsDirectory,可以区分文件夹和文件DirectoryListParser类代码如下:
DirectoryListParserusing&Susing&System.IO;using&System.Nusing&System.Text.RegularEusing&System.Cusing&System.Collections.Gnamespace&WindowsApplicationFTP{&&&&public&struct&FileStruct&&&&{&&&&&&&&public&string&F&&&&&&&&public&string&O&&&&&&&&public&bool&IsD&&&&&&&&public&string&CreateT&&&&&&&&public&string&N&&&&}&&&&public&enum&FileListStyle&&&&{&&&&&&&&UnixStyle,&&&&&&&&WindowsStyle,&&&&&&&&Unknown&&&&}&&&&public&class&DirectoryListParser&&&&{&&&&&&&&private&List&FileStruct&&_myListA&&&&&&&&public&FileStruct[]&FullListing&&&&&&&&{&&&&&&&&&&&&get&&&&&&&&&&&&{&&&&&&&&&&&&&&&&return&_myListArray.ToArray();&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&}&&&&&&&&public&FileStruct[]&FileList&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&get&&&&&&&&&&&&{&&&&&&&&&&&&&&&&List&FileStruct&&_fileList&=&new&List&FileStruct&();&&&&&&&&&&&&&&&&foreach(FileStruct&thisstruct&in&_myListArray)&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&if(!thisstruct.IsDirectory)&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&_fileList.Add(thisstruct);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&return&_fileList.ToArray();&&&&&&&&&&&&}&&&&&&&&}&&&&&&&&public&FileStruct[]&DirectoryList&&&&&&&&{&&&&&&&&&&&&get&&&&&&&&&&&&{&&&&&&&&&&&&&&&&List&FileStruct&&_dirList&=&new&List&FileStruct&();&&&&&&&&&&&&&&&&foreach(FileStruct&thisstruct&in&_myListArray)&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&if(thisstruct.IsDirectory)&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&_dirList.Add(thisstruct);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&return&_dirList.ToArray();&&&&&&&&&&&&}&&&&&&&&}&&&&&&&&public&DirectoryListParser(string&responseString)&&&&&&&&{&&&&&&&&&&&&_myListArray&=&GetList(responseString);&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&private&List&FileStruct&&GetList(string&datastring)&&&&&&&&{&&&&&&&&&&&&List&FileStruct&&myListArray&=&new&List&FileStruct&();&&&&&&&&&&&&&string[]&dataRecords&=&datastring.Split('\n');&&&&&&&&&&&&FileListStyle&_directoryListStyle&=&GuessFileListStyle(dataRecords);&&&&&&&&&&&&foreach&(string&s&in&dataRecords)&&&&&&&&&&&&{&&&&&&&&&&&&&&&&if&(_directoryListStyle&!=&FileListStyle.Unknown&&&&s&!=&"")&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&FileStruct&f&=&new&FileStruct();&&&&&&&&&&&&&&&&&&&&f.Name&=&"..";&&&&&&&&&&&&&&&&&&&&switch&(_directoryListStyle)&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&case&FileListStyle.UnixStyle:&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&f&=&ParseFileStructFromUnixStyleRecord(s);&&&&&&&&&&&&&&&&&&&&&&&&&&&&break;&&&&&&&&&&&&&&&&&&&&&&&&case&FileListStyle.WindowsStyle:&&&&&&&&&&&&&&&&&&&&&&&&&&&&f&=&ParseFileStructFromWindowsStyleRecord(s);&&&&&&&&&&&&&&&&&&&&&&&&&&&&break;&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&if&(f.Name&!=&""&&&&f.Name&!=&"."&&&&f.Name&!=&"..")&&&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&&&&myListArray.Add(f);&&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&}&&&&&&&&&&&&}&&&&&&&&&&&&return&myListA&&&&&&&&}&&&&&&&&&&&&&&&&private&FileStruct&ParseFileStructFromWindowsStyleRecord(string&Record)&&&&&&&&{&&&&&&&&&&&&///Assuming&the&record&style&as&&&&&&&&&&&&&///&02-03-04&&07:46PM&&&&&&&&DIR&&&&&&&&&&&Append&&&&&&&&&&&&FileStruct&f&=&new&FileStruct();&&&&&&&&&&&&string&processstr&=&Record.Trim();&&&&&&&&&&&&string&dateStr&=&processstr.Substring(0,8);&&&&&&&&&&&&&&&&&&processstr&=&(processstr.Substring(8,&processstr.Length&-&8)).Trim();&&&&&&&&&&&&string&timeStr&=&processstr.Substring(0,&7);&&&&&&&&&&&&processstr&=&(processstr.Substring(7,&processstr.Length&-&7)).Trim();&&&&&&&&&&&&f.CreateTime&=&dateStr&+&"&"&+&timeS&&&&&&&&&&&&if&(processstr.Substring(0,5)&==&"&DIR&")&&&&&&&&&&&&{&&&&&&&&&&&&&&&&f.IsDirectory&=&true;&&&&&&&&&&&&&&&&&&&&processstr&=&(processstr.Substring(5,&processstr.Length&-&5)).Trim();&&&&&&&&&&&&}&&&&&&&&&&&&else&&&&&&&&&&&&{&&&&&&&&&&&&&&&&string[]&strs&=&processstr.Split(new&char[]&{&'&'&},&StringSplitOptions.RemoveEmptyEntries);&&&&&&&&&&&&&&&&processstr&=&strs[1];&&&&&&&&&&&&&&&&f.IsDirectory&=&false;&&&&&&&&&&&&}&&&&&&&&&&&&f.Name&=&&&//Rest&is&name&&&&&&&&&&&&&&&return&f;&&&&&&&&}&&&&&&&&&&&&&&&&public&FileListStyle&GuessFileListStyle(string[]&recordList)&&&&&&&&{&&&&&&&&&&&&foreach&(string&s&in&recordList)&&&&&&&&&&&&{&&&&&&&&&&&&&&&&if(s.Length&&&10&&&&&&&&&&&&&&&&&&&&&&&&Regex.IsMatch(s.Substring(0,10),"(-|d)((-|r)(-|w)(-|x)){3}"))&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&return&FileListStyle.UnixS&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&else&if&(s.Length&&&8&&&&&&&&&&&&&&&&&&&&&&&&Regex.IsMatch(s.Substring(0,&8),&&"[0-9]{2}-[0-9]{2}-[0-9]{2}"))&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&return&FileListStyle.WindowsS&&&&&&&&&&&&&&&&}&&&&&&&&&&&&}&&&&&&&&&&&&return&FileListStyle.U&&&&&&&&}&&&&&&&&&&&&&&&&private&FileStruct&ParseFileStructFromUnixStyleRecord(string&record)&&&&&&&&{&&&&&&&&&&&&///Assuming&record&style&as&&&&&&&&&&&&///&dr-xr-xr-x&&&1&owner&&&&group&&&&&&&&&&&&&&&0&Nov&25&&2002&bussys&&&&&&&&&&&&FileStruct&f&=&new&FileStruct();&&&&&&&&&&&&if&(record[0]&==&'-'&||&record[0]&==&'d')&&&&&&&&&&&&{//&its&a&valid&file&record&&&&&&&&&&&&&&&&string&processstr&=&record.Trim();&&&&&&&&&&&&&&&&f.Flags&=&processstr.Substring(0,&9);&&&&&&&&&&&&&&&&f.IsDirectory&=&(f.Flags[0]&==&'d');&&&&&&&&&&&&&&&&processstr&=&(processstr.Substring(11)).Trim();&&&&&&&&&&&&&&&&_cutSubstringFromStringWithTrim(ref&processstr,&'&',&0);&&&//skip&one&part&&&&&&&&&&&&&&&&f.Owner&=&_cutSubstringFromStringWithTrim(ref&processstr,&'&',&0);&&&&&&&&&&&&&&&&f.CreateTime&=&getCreateTimeString(record);&&&&&&&&&&&&&&&&int&fileNameIndex&=&record.IndexOf(f.CreateTime)+f.CreateTime.L&&&&&&&&&&&&&&&&f.Name&=&record.Substring(fileNameIndex).Trim();&&&//Rest&of&the&part&is&name&&&&&&&&&&&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&else&&&&&&&&&&&&{&&&&&&&&&&&&&&&&f.Name&=&"";&&&&&&&&&&&&}&&&&&&&&&&&&return&f;&&&&&&&&}&&&&&&&&private&string&getCreateTimeString(string&record)&&&&&&&&{&&&&&&&&&&&&//Does&just&basic&datetime&string&validation&for&demo,&not&an&accurate&check&&&&&&&&&&&&//on&date&and&time&fields&&&&&&&&&&&&string&month&=&"(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)";&&&&&&&&&&&&string&space&=&@"(\040)+";&&&&&&&&&&&&string&day&=&"([0-9]|[1-3][0-9])";&&&&&&&&&&&&string&year&=&"[1-2][0-9]{3}";&&&&&&&&&&&&string&time&=&"[0-9]{1,2}:[0-9]{2}";&&&&&&&&&&&&&&&&&&&&&&&&Regex&dateTimeRegex&=&new&Regex(month+space+day+space+"("+year+"|"+time+")",&RegexOptions.IgnoreCase);&&&&&&&&&&&&Match&match&=&dateTimeRegex.Match(record);&&&&&&&&&&&&return&match.V&&&&&&&&}&&&&&&&&&&&&&&&&private&string&_cutSubstringFromStringWithTrim(ref&string&s,&char&c,&int&startIndex)&&&&&&&&{&&&&&&&&&&&&int&pos1&=&s.IndexOf(c,&startIndex);&&&&&&&&&&&&string&retString&=&s.Substring(0,pos1);&&&&&&&&&&&&s&=&(s.Substring(pos1)).Trim();&&&&&&&&&&&&return&retS&&&&&&&}&&&&}}
2.取ftp登陆身份验证完成后的欢迎信息关键知识说明:a.FtpWebResponse.WelcomeMessage属性获取身份验证完成时FTP服务器发送的消息
实例代码:获取登陆身份验证完成后的欢迎信息Uri uri = new Uri ( "" );
FtpWebRequest listRequest = ( FtpWebRequest ) WebRequest.Create ( uri );
listRequest.Method = WebRequestMethods.Ftp.ListDirectoryD
string ftpUser = "";string ftpPassWord = "";listRequest.Credentials = new NetworkCredential ( ftpUser , ftpPassWord );
FtpWebResponse listResponse = ( FtpWebResponse ) listRequest.GetResponse ( );
MessageBox.Show ( listResponse.WelcomeMessage );
附加说明:要是FTP服务器的欢迎信息带有中文,运行这段代码时可能会发生异常(基础连接已经关闭: 服务器提交了协议).解决办法:打补丁Microsoft .NET Framework 2.0 Service Pack 1
3.重命名目录关键知识说明:a.WebRequestMethods.Ftp.Rename表示重命名目录的FTP协议方法b.FtpWebRequest.RenameTo属性重命名的新名称
实例代码:把上的a目录重命名为avUri uri = new Uri ( "" );
FtpWebRequest listRequest = ( FtpWebRequest ) WebRequest.Create ( uri );
listRequest.Method = WebRequestMethods.Ftp.R
string ftpUser = "";string ftpPassWord = "";listRequest.Credentials = new NetworkCredential ( ftpUser , ftpPassWord );
listRequest.RenameTo = "av";
FtpWebResponse listResponse = ( FtpWebResponse ) listRequest.GetResponse ( );
MessageBox.Show ( listResponse.StatusDescription );
4.删除目录关键知识说明:a.WebRequestMethods.Ftp.RemoveDirectory表示移除目录的FTP协议方法
实例代码:删除上的av文件夹Uri uri = new Uri ( "" );
FtpWebRequest listRequest = ( FtpWebRequest ) WebRequest.Create ( uri );
listRequest.Method = WebRequestMethods.Ftp.RemoveD
string ftpUser = "";string ftpPassWord = "";listRequest.Credentials = new NetworkCredential ( ftpUser , ftpPassWord );
FtpWebResponse listResponse = ( FtpWebResponse ) listRequest.GetResponse ( );&&&&
MessageBox.Show ( listResponse.StatusDescription );
5.新建目录关键知识说明:a.WebRequestMethods.Ftp.MakeDirectory表示在FTP服务器上创建目录的协议方法
实例代码:在上建立目录vbUri uri = new Uri ( "" );
FtpWebRequest listRequest = ( FtpWebRequest ) WebRequest.Create ( uri );
listRequest.Method = WebRequestMethods.Ftp.MakeD
string ftpUser = "";string ftpPassWord = "";listRequest.Credentials = new NetworkCredential ( ftpUser , ftpPassWord );
FtpWebResponse listResponse = ( FtpWebResponse ) listRequest.GetResponse ( );
MessageBox.Show ( listResponse.StatusDescription );
6.得文件大小关键知识说明:a.WebRequestMethods.Ftp.GetFileSize表示要用于检索FTP服务器上的文件大小b.流数据的长度可以从FtpWebResponse.ContentLength属性中获取。
实例代码:获取上的会议记录.doc文件大小Uri uri = new Uri ( "会议记录.doc" );
FtpWebRequest listRequest = ( FtpWebRequest ) WebRequest.Create ( uri );
listRequest.Method = WebRequestMethods.Ftp.GetFileS
string ftpUser = "";string ftpPassWord = "";listRequest.Credentials = new NetworkCredential ( ftpUser , ftpPassWord );
FtpWebResponse listResponse = ( FtpWebResponse ) listRequest.GetResponse ( );
MessageBox.Show ( string.Format ( "文件大小: {0}" , listResponse.ContentLength ) );
7.删除文件关键知识说明:a.WebRequestMethods.Ftp.DeleteFile表示要用于删除FTP服务器上的文件
实例代码:删除上的工作安排.txt文件Uri uri = new Uri ( "工作安排.txt" );
FtpWebRequest listRequest = ( FtpWebRequest ) WebRequest.Create ( uri );
listRequest.Method = WebRequestMethods.Ftp.DeleteF
string ftpUser = "";string ftpPassWord = "";listRequest.Credentials = new NetworkCredential ( ftpUser , ftpPassWord );
FtpWebResponse listResponse = ( FtpWebResponse ) listRequest.GetResponse ( );
MessageBox.Show ( string.Format ( "Delete status: {0}" , listResponse.StatusDescription ) );
8.上传文件关键知识说明:a.WebRequestMethods.Ftp.UploadFile表示将文件上载到FTP服务器b.使用FtpWebRequest对象向服务器上载文件,则必须将文件内容写入请求流,请求流是通过调用FtpWebRequest.GetRequestStream方法.如果未将属性设置为UploadFile,则不能获取流。c.异步对应方法(FtpWebRequest.BeginGetRequestStream方法和FtpWebRequest.EndGetRequestStream 方法),关于异步上传的实现我会再写在下篇总汇中
实例代码:上载文件D:\abc.txt到上Stream requestStream =FileStream fileStream =FtpWebResponse uploadResponse =
try{&&& Uri uri = new Uri ( "" );
&&& FtpWebRequest uploadRequest = ( FtpWebRequest ) WebRequest.Create ( uri );&&& uploadRequest.Method = WebRequestMethods.Ftp.UploadF
&&& string ftpUser = "";&&& string ftpPassWord = "";&&& uploadRequest.Credentials = new NetworkCredential ( ftpUser , ftpPassWord );
&&& requestStream = uploadRequest.GetRequestStream ( );&&& fileStream = File.Open ( @"D:\abc.txt" , FileMode.Open );
&&& byte [ ] buffer = new byte [ 1024 ];&&& int bytesR&&& while ( true )&&& {&&&&&&& bytesRead = fileStream.Read ( buffer , 0 , buffer.Length );&&&&&&& if ( bytesRead == 0 )&&&&&&&&&&&&&&&&&& requestStream.Write ( buffer , 0 , bytesRead );&&& }
&&& requestStream.Close ( );
&&& uploadResponse = ( FtpWebResponse ) uploadRequest.GetResponse ( );
&&& MessageBox.Show ( "Upload complete." );}finally{&&& if ( uploadResponse != null )&&&&&&& uploadResponse.Close ( );&&& if ( fileStream != null )&&&&&&& fileStream.Close ( );&&& if ( requestStream != null )&&&&&&& requestStream.Close ( );}
其实利用WebClient.UploadData方法,还有一种更简单的上传方法:WebClient request = new WebClient ( );
string ftpUser = "";string ftpPassWord = "";request.Credentials = new NetworkCredential ( ftpUser , ftpPassWord );
FileStream myStream = new FileStream ( @"D:\abcd.txt" , FileMode.Open , FileAccess.Read );byte [ ] dataByte = new byte [ myStream.Length ];myStream.Read ( dataByte , 0 , dataByte.Length );&&//写到2进制数组中myStream.Close ( );
request.UploadData ( "" , dataByte );
9.下载文件关键知识说明:a.WebRequestMethods.Ftp.DownloadFile表示要用于从FTP服务器下载文件b.从FTP服务器下载文件时,如果命令成功,所请求的文件的内容即在响应对象的流中。通过调用FtpWebResponse.GetResponseStream方法,可以访问此流。
实例代码:从上下载文件保存到d:\abc.txtStream responseStream =FileStream fileStream =StreamReader reader =
try{&&& string downloadUrl = "";
&&& FtpWebRequest downloadRequest = ( FtpWebRequest ) WebRequest.Create ( downloadUrl );&&& downloadRequest.Method = WebRequestMethods.Ftp.DownloadF
&&& string ftpUser = "";&&& string ftpPassWord = "";&&& downloadRequest.Credentials = new NetworkCredential ( ftpUser , ftpPassWord );
&&& FtpWebResponse downloadResponse = ( FtpWebResponse ) downloadRequest.GetResponse ( );&&& responseStream = downloadResponse.GetResponseStream ( );
&&& fileStream = File.Create ( @"d:\" + "abc.txt" );&&& byte [ ] buffer = new byte [ 1024 ];&&& int bytesR&&& while ( true )&&& {&&&&&&& bytesRead = responseStream.Read ( buffer , 0 , buffer.Length );&&&&&&& if ( bytesRead == 0 )&&&&&&&&&&&&&&&&&& fileStream.Write ( buffer , 0 , bytesRead );&&& }&&& &&& MessageBox.Show ( "Download complete" );}finally{&&& if ( reader != null )&&& {&&&&&&& reader.Close ( );&&& }&&& else&&& {&&&&&&& if ( responseStream != null )&&&&&&& {&&&&&&&&&&& responseStream.Close ( );&&&&&&& }&&&&&&& if ( fileStream != null )&&&&&&& {&&&&&&&&&&& fileStream.Close ( );&&&&&&& }&&& }}
其实利用WebClient.DownloadData方法,还有一种更简单的下载方法:Uri uri = new Uri ( "" );
WebClient request = new WebClient ( );
string ftpUser = "";string ftpPassWord = "";request.Credentials = new NetworkCredential ( ftpUser , ftpPassWord );
byte [ ] newFileData = request.DownloadData ( uri.ToString ( ) );
FileStream fs = new FileStream ( @"d:\abc.txt" , FileMode.OpenOrCreate , FileAccess.Write );fs.Write ( newFileData , 0 , newFileData.Length );fs.Close ( );
10.2个ftp间传送文件关键知识说明:a.在搞懂前面所说下载和上传知识后,其实很好实现2个ftp间传送文件.我们可以把传送文件看成是先下载后上传.把下载的文件响应流数据写到上传文件请求流中即可.
实例代码:把中"集团公司通知"目录中的"080124-成本费用科目调整通知.pdf"文件传送到string downloadUrl = "集团公司通知/080124-成本费用科目调整通知.pdf";FtpWebRequest downloadRequest = ( FtpWebRequest ) WebRequest.Create ( downloadUrl );downloadRequest.Method = WebRequestMethods.Ftp.DownloadF
string ftpUser = "download";string ftpPassWord = "download";downloadRequest.Credentials = new NetworkCredential ( ftpUser , ftpPassWord );
string uploadUrl = "-成本费用科目调整通知.pdf";FtpWebRequest uploadRequest = ( FtpWebRequest ) WebRequest.Create ( uploadUrl );uploadRequest.Method = WebRequestMethods.Ftp.UploadF
string ftpUser1 = "exwangsoft";string ftpPassWord1 = "exwangsoft";uploadRequest.Credentials = new NetworkCredential ( ftpUser1 , ftpPassWord1 );
FtpWebResponse downloadResponse = ( FtpWebResponse ) downloadRequest.GetResponse ( );Stream responseStream = downloadResponse.GetResponseStream ( );
Stream fileStream = uploadRequest.GetRequestStream ( );byte [ ] buffer = new byte [ 1024 ];int bytesRwhile ( true ){&&& //读取的响应流数据&&& bytesRead = responseStream.Read ( buffer , 0 , buffer.Length );&&& if ( bytesRead == 0 )&&&&&&&&&& //写到的请求流数据中&&& fileStream.Write ( buffer , 0 , bytesRead );}
fileStream.Close ( );FtpWebResponse uploadResponse =uploadResponse = ( FtpWebResponse ) uploadRequest.GetResponse ( );
MessageBox.Show ( "complete" );最后做个广告:成立,!
收藏与分享
RSS订阅我&
&& && && && && && && && &&
东莞.net俱乐部
阅读(...) 评论()投放本站广告请联系:
Sencha相关书籍
对话框(MessageBox)
Posted 周二, 06/17/2008 - 14:03 by
ExtJs中的消息对话框一样是最吸引我们的地方,为你的页面添加了许多新的元素.出来的对话框不再是千篇一律的浏览器自带的样式.
演示(demo)地址在文章最后.
ExtJs中的消息对话框一样是最吸引我们的地方,为你的页面添加了许多新的元素.出来的对话框不再是千篇一律的浏览器自带的样式.
演示(demo)地址在文章最后.
例子包括两个文件msg-box.html 和 msg-box.js
msg-box.html
&meta http-equiv="Content-Type" content="text/ charset=iso-8859-1"&
&title&MessageBox&/title&
&link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" /&
&!-- GC --&
&!-- LIBS --&
&script type="text/javascript" src="../../adapter/ext/ext-base.js"&&/script&
&!-- ENDLIBS --&
&script type="text/javascript" src="../../ext-all.js"&&/script&
&script type="text/javascript" src="msg-box.js"&&/script&
&!-- Common Styles for the examples --&
&link rel="stylesheet" type="text/css" href="../examples.css" /&
&style type="text/css"&
.x-window-dlg .ext-mb-download {
background:transparent url(images/download.gif) no-
&script type="text/javascript" src="../examples.js"&&/script&&!-- EXAMPLES --&
&h1&MessageBox Dialogs&/h1&
&p&The example shows how to use the MessageBox class. Some of the buttons have animations, some are normal.&/p&
&p&The js is not minified so it is readable. See &a href="msg-box.js"&msg-box.js&/a&.&/p&
&b&Confirm&/b&&br /&
Standard Yes/No dialog.
&button id="mb1"&Show&/button&
&b&Prompt&/b&&br /&
Standard prompt dialog.
&button id="mb2"&Show&/button&
&b&Multi-line Prompt&/b&&br /&
A multi-line prompt dialog.
&button id="mb3"&Show&/button&
&b&Yes/No/Cancel&/b&&br /&
Standard Yes/No/Cancel dialog.
&button id="mb4"&Show&/button&
&b&Progress Dialog&/b&&br /&
Dialog with measured progress bar.
&button id="mb6"&Show&/button&
&b&Wait Dialog&/b&&br /&
Dialog with indefinite progress bar and custom icon (will close after 8 sec).
&button id="mb7"&Show&/button&
&b&Alert&/b&&br /&
Standard alert message dialog.
&button id="mb8"&Show&/button&
&b&Icons&/b&&br /&
Standard alert with optional icon.
&select id="icons"&
&option id="error" selected="selected"&Error&/option&
&option id="info"&Informational&/option&
&option id="question"&Question&/option&
&option id="warning"&Warning&/option&
&button id="mb9"&Show&/button&
msg-box.js
* Ext JS Library 2.0.2
* Copyright(c) , Ext JS, LLC.
* licensing@
* /license
Ext.onReady(function(){
Ext.get('mb1').on('click', function(e){
Ext.MessageBox.confirm('Confirm', 'Are you sure you want to do that?', showResult);
Ext.get('mb2').on('click', function(e){
Ext.MessageBox.prompt('Name', 'Please enter your name:', showResultText);
Ext.get('mb3').on('click', function(e){
Ext.MessageBox.show({
title: 'Address',
msg: 'Please enter your address:',
width:300,
buttons: Ext.MessageBox.OKCANCEL,
multiline: true,
fn: showResultText,
animEl: 'mb3'
Ext.get('mb4').on('click', function(e){
Ext.MessageBox.show({
title:'Save Changes?',
msg: 'You are closing a tab that has unsaved changes. &br /&Would you like to save your changes?',
buttons: Ext.MessageBox.YESNOCANCEL,
fn: showResult,
animEl: 'mb4',
icon: Ext.MessageBox.QUESTION
Ext.get('mb6').on('click', function(){
Ext.MessageBox.show({
title: 'Please wait',
msg: 'Loading items...',
progressText: 'Initializing...',
width:300,
progress:true,
closable:false,
animEl: 'mb6'
// this hideous block creates the bogus progress
var f = function(v){
return function(){
if(v == 12){
Ext.MessageBox.hide();
Ext.example.msg('Done', 'Your fake items were loaded!');
var i = v/11;
Ext.MessageBox.updateProgress(i, Math.round(100*i)+'% completed');
for(var i = 1; i & 13; i++){
setTimeout(f(i), i*500);
Ext.get('mb7').on('click', function(){
Ext.MessageBox.show({
msg: 'Saving your data, please wait...',
progressText: 'Saving...',
width:300,
wait:true,
waitConfig: {interval:200},
icon:'ext-mb-download', //custom class in msg-box.html
animEl: 'mb7'
setTimeout(function(){
//This simulates a long-running operation like a database save or XHR call.
//In real code, this would be in a callback function.
Ext.MessageBox.hide();
Ext.example.msg('Done', 'Your fake data was saved!');
Ext.get('mb8').on('click', function(){
Ext.MessageBox.alert('Status', 'Changes saved successfully.', showResult);
//Add these values dynamically so they aren't hard-coded in the html
Ext.fly('info').dom.value = ;
Ext.fly('question').dom.value = Ext.MessageBox.QUESTION;
Ext.fly('warning').dom.value = Ext.MessageBox.WARNING;
Ext.fly('error').dom.value = Ext.MessageBox.ERROR;
Ext.get('mb9').on('click', function(){
Ext.MessageBox.show({
title: 'Icon Support',
msg: 'Here is a message with an icon!',
buttons: Ext.MessageBox.OK,
animEl: 'mb9',
fn: showResult,
icon: Ext.get('icons').dom.value
function showResult(btn){
Ext.example.msg('Button Click', 'You clicked the {0} button', btn);
function showResultText(btn, text){
Ext.example.msg('Button Click', 'You clicked the {0} button and entered the text "{1}".', btn, text);
var tbar = new Ext.Toolbar({
ref:'../but1'
var grid =
Ext.grid.GridPanel({
alert(grid.but1) 结果 [object object]
alert(grid.but1)
请帮忙分析一下
Waaaaaa和良好work.I想成为一名网页设计师,是要清除 。和以及其他重要的一个
这些考试/证书考虑在IT领域的土地的标志。我希望会有一个单独的部分为
以及与此相关的其他条款。
本站采用创作共用版权协议, 要求署名、非商业用途和保持一致. 转载本站内容必须也遵循“署名-非商业用途-保持一致”的创作共用协议.

我要回帖

更多关于 vfp messagebox 的文章

 

随机推荐