关键词搜索

源码搜索 ×
×

C# 上传下载ftp(支持断点续传)

发布2015-11-25浏览9492次

详情内容

本文整理自网络,由于太多文章类似,此处标识其中一处:点击打开链接

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Net.Sockets;
  6. using System.IO;
  7. using System.Net;
  8. namespace JianKunKing.Common.Ftp
  9. {
  10. /// <summary>
  11. /// FTP Client(不允许匿名登录)
  12. /// 上传、下载已测试,其余未测试
  13. /// </summary>
  14. public class FTPClient
  15. {
  16. #region 构造函数
  17. /// <summary>
  18. /// 缺省构造函数
  19. /// </summary>
  20. public FTPClient()
  21. {
  22. this.ftpServerIP = "";
  23. this.remoteFilePath = "";
  24. this.ftpUserID = "";
  25. this.ftpPassword = "";
  26. this.ftpServerPort = 21;
  27. this.bConnected = false;
  28. }
  29. /// <summary>
  30. /// 构造函数
  31. /// </summary>
  32. /// <param name="remoteHost">FTP服务器IP地址</param>
  33. /// <param name="remotePath">当前服务器目录</param>
  34. /// <param name="remoteUser">Ftp 服务器登录用户账号</param>
  35. /// <param name="remotePass">Ftp 服务器登录用户密码</param>
  36. /// <param name="remotePort">FTP服务器端口</param>
  37. public FTPClient(string ftpServerIP, string remoteFilePath, string ftpUserID, string ftpPassword, int ftpServerPort, bool anonymousAccess = false)
  38. {
  39. this.ftpServerIP = ftpServerIP;
  40. this.remoteFilePath = remoteFilePath;
  41. this.ftpUserID = ftpUserID;
  42. this.ftpPassword = ftpPassword;
  43. this.ftpServerPort = ftpServerPort;
  44. this.Connect();
  45. }
  46. #endregion
  47. #region 登陆字段、属性
  48. /// <summary>
  49. /// FTP服务器IP地址
  50. /// </summary>
  51. private string ftpServerIP;
  52. public string FtpServerIP
  53. {
  54. get
  55. {
  56. return ftpServerIP;
  57. }
  58. set
  59. {
  60. this.ftpServerIP = value;
  61. }
  62. }
  63. /// <summary>
  64. /// FTP服务器端口
  65. /// </summary>
  66. private int ftpServerPort;
  67. public int FtpServerPort
  68. {
  69. get
  70. {
  71. return ftpServerPort;
  72. }
  73. set
  74. {
  75. this.ftpServerPort = value;
  76. }
  77. }
  78. /// <summary>
  79. /// 当前服务器目录
  80. /// </summary>
  81. private string remoteFilePath;
  82. public string RemoteFilePath
  83. {
  84. get
  85. {
  86. return remoteFilePath;
  87. }
  88. set
  89. {
  90. this.remoteFilePath = value;
  91. }
  92. }
  93. /// <summary>
  94. /// Ftp 服务器登录用户账号
  95. /// </summary>
  96. private string ftpUserID;
  97. public string FtpUserID
  98. {
  99. set
  100. {
  101. this.ftpUserID = value;
  102. }
  103. }
  104. /// <summary>
  105. /// Ftp 服务器用户登录密码
  106. /// </summary>
  107. private string ftpPassword;
  108. public string FtpPassword
  109. {
  110. set
  111. {
  112. this.ftpPassword = value;
  113. }
  114. }
  115. /// <summary>
  116. /// 是否登录
  117. /// </summary>
  118. private bool bConnected;
  119. public bool Connected
  120. {
  121. get
  122. {
  123. return this.bConnected;
  124. }
  125. }
  126. #endregion
  127. #region 链接
  128. /// <summary>
  129. /// 建立连接
  130. /// </summary>
  131. public void Connect()
  132. {
  133. socketControl = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  134. IPEndPoint ep = new IPEndPoint(IPAddress.Parse(FtpServerIP), ftpServerPort);
  135. // 链接
  136. try
  137. {
  138. socketControl.Connect(ep);
  139. }
  140. catch (Exception)
  141. {
  142. throw new IOException("Couldn't connect to remote server");
  143. }
  144. // 获取应答码
  145. ReadReply();
  146. if (iReplyCode != 220)
  147. {
  148. DisConnect();
  149. throw new IOException(strReply.Substring(4));
  150. }
  151. // 登陆
  152. SendCommand("USER " + ftpUserID);
  153. if (!(iReplyCode == 331 || iReplyCode == 230))
  154. {
  155. CloseSocketConnect();//关闭连接
  156. throw new IOException(strReply.Substring(4));
  157. }
  158. if (iReplyCode != 230)
  159. {
  160. SendCommand("PASS " + ftpPassword);
  161. if (!(iReplyCode == 230 || iReplyCode == 202))
  162. {
  163. CloseSocketConnect();//关闭连接
  164. throw new IOException(strReply.Substring(4));
  165. }
  166. }
  167. bConnected = true;
  168. // 切换到初始目录
  169. if (!string.IsNullOrEmpty(remoteFilePath))
  170. {
  171. ChDir(remoteFilePath);
  172. }
  173. }
  174. /// <summary>
  175. /// 关闭连接
  176. /// </summary>
  177. public void DisConnect()
  178. {
  179. if (socketControl != null)
  180. {
  181. SendCommand("QUIT");
  182. }
  183. CloseSocketConnect();
  184. }
  185. #endregion
  186. #region 传输模式
  187. /// <summary>
  188. /// 传输模式:二进制类型、ASCII类型
  189. /// </summary>
  190. public enum TransferType
  191. {
  192. Binary,
  193. ASCII
  194. };
  195. /// <summary>
  196. /// 设置传输模式
  197. /// </summary>
  198. /// <param name="ttType">传输模式</param>
  199. public void SetTransferType(TransferType ttType)
  200. {
  201. if (ttType == TransferType.Binary)
  202. {
  203. SendCommand("TYPE I");//binary类型传输
  204. }
  205. else
  206. {
  207. SendCommand("TYPE A");//ASCII类型传输
  208. }
  209. if (iReplyCode != 200)
  210. {
  211. throw new IOException(strReply.Substring(4));
  212. }
  213. else
  214. {
  215. trType = ttType;
  216. }
  217. }
  218. /// <summary>
  219. /// 获得传输模式
  220. /// </summary>
  221. /// <returns>传输模式</returns>
  222. public TransferType GetTransferType()
  223. {
  224. return trType;
  225. }
  226. #endregion
  227. #region 文件操作
  228. /// <summary>
  229. /// 获得文件列表
  230. /// </summary>
  231. /// <param name="strMask">文件名的匹配字符串</param>
  232. /// <returns></returns>
  233. public string[] Dir(string strMask)
  234. {
  235. // 建立链接
  236. if (!bConnected)
  237. {
  238. Connect();
  239. }
  240. //建立进行数据连接的socket
  241. Socket socketData = CreateDataSocket();
  242. //传送命令
  243. SendCommand("LIST " + strMask);
  244. //分析应答代码
  245. if (!(iReplyCode == 150 || iReplyCode == 125 || iReplyCode == 226))
  246. {
  247. throw new IOException(strReply.Substring(4));
  248. }
  249. //获得结果
  250. strMsg = "";
  251. while (true)
  252. {
  253. int iBytes = socketData.Receive(buffer, buffer.Length, 0);
  254. strMsg += GB2312.GetString(buffer, 0, iBytes);
  255. if (iBytes < buffer.Length)
  256. {
  257. break;
  258. }
  259. }
  260. char[] seperator = { '\n' };
  261. string[] strsFileList = strMsg.Split(seperator);
  262. socketData.Close();//数据socket关闭时也会有返回码
  263. if (iReplyCode != 226)
  264. {
  265. ReadReply();
  266. if (iReplyCode != 226)
  267. {
  268. throw new IOException(strReply.Substring(4));
  269. }
  270. }
  271. return strsFileList;
  272. }
  273. /// <summary>
  274. /// 获取文件大小
  275. /// </summary>
  276. /// <param name="strFileName">文件名</param>
  277. /// <returns>文件大小</returns>
  278. public long GetFileSize(string strFileName)
  279. {
  280. if (!bConnected)
  281. {
  282. Connect();
  283. }
  284. SendCommand("SIZE " + Path.GetFileName(strFileName));
  285. long lSize = 0;
  286. if (iReplyCode == 213)
  287. {
  288. lSize = Int64.Parse(strReply.Substring(4));
  289. }
  290. else
  291. {
  292. throw new IOException(strReply.Substring(4));
  293. }
  294. return lSize;
  295. }
  296. /// <summary>
  297. /// 删除
  298. /// </summary>
  299. /// <param name="strFileName">待删除文件名</param>
  300. public void Delete(string strFileName)
  301. {
  302. if (!bConnected)
  303. {
  304. Connect();
  305. }
  306. SendCommand("DELE " + strFileName);
  307. if (iReplyCode != 250)
  308. {
  309. throw new IOException(strReply.Substring(4));
  310. }
  311. }
  312. /// <summary>
  313. /// 重命名(如果新文件名与已有文件重名,将覆盖已有文件)
  314. /// </summary>
  315. /// <param name="strOldFileName">旧文件名</param>
  316. /// <param name="strNewFileName">新文件名</param>
  317. public void Rename(string strOldFileName, string strNewFileName)
  318. {
  319. if (!bConnected)
  320. {
  321. Connect();
  322. }
  323. SendCommand("RNFR " + strOldFileName);
  324. if (iReplyCode != 350)
  325. {
  326. throw new IOException(strReply.Substring(4));
  327. }
  328. // 如果新文件名与原有文件重名,将覆盖原有文件
  329. SendCommand("RNTO " + strNewFileName);
  330. if (iReplyCode != 250)
  331. {
  332. throw new IOException(strReply.Substring(4));
  333. }
  334. }
  335. #endregion
  336. #region 上传和下载
  337. /// <summary>
  338. /// 下载一批文件
  339. /// </summary>
  340. /// <param name="strFileNameMask">文件名的匹配字符串</param>
  341. /// <param name="strFolder">本地目录(不得以\结束)</param>
  342. public void Download(string strFileNameMask, string strFolder)
  343. {
  344. if (!bConnected)
  345. {
  346. Connect();
  347. }
  348. string[] strFiles = Dir(strFileNameMask);
  349. foreach (string strFile in strFiles)
  350. {
  351. if (!strFile.Equals(""))//一般来说strFiles的最后一个元素可能是空字符串
  352. {
  353. if (strFile.LastIndexOf(".") > -1)
  354. {
  355. Download(strFile.Replace("\r", ""), strFolder, strFile.Replace("\r", ""));
  356. }
  357. }
  358. }
  359. }
  360. /// <summary>
  361. /// 下载目录
  362. /// </summary>
  363. /// <param name="strRemoteFileName">要下载的文件名</param>
  364. /// <param name="strFolder">本地目录(不得以\结束)</param>
  365. /// <param name="strLocalFileName">保存在本地时的文件名</param>
  366. public void Download(string strRemoteFileName, string strFolder, string strLocalFileName)
  367. {
  368. if (strLocalFileName.StartsWith("-r"))
  369. {
  370. string[] infos = strLocalFileName.Split(' ');
  371. strRemoteFileName = strLocalFileName = infos[infos.Length - 1];
  372. if (!this.bConnected)
  373. {
  374. this.Connect();
  375. }
  376. SetTransferType(TransferType.Binary);
  377. if (strLocalFileName.Equals(""))
  378. {
  379. strLocalFileName = strRemoteFileName;
  380. }
  381. if (!File.Exists(strLocalFileName))
  382. {
  383. Stream st = File.Create(strLocalFileName);
  384. st.Close();
  385. }
  386. FileStream output = new
  387. FileStream(strFolder + "\\" + strLocalFileName, FileMode.Create);
  388. Socket socketData = CreateDataSocket();
  389. SendCommand("RETR " + strRemoteFileName);
  390. if (!(iReplyCode == 150 || iReplyCode == 125
  391. || iReplyCode == 226 || iReplyCode == 250))
  392. {
  393. throw new IOException(strReply.Substring(4));
  394. }
  395. int receiveBytes = 0;
  396. while (true)
  397. {
  398. int iBytes = socketData.Receive(buffer, buffer.Length, 0);
  399. receiveBytes = receiveBytes + iBytes;
  400. output.Write(buffer, 0, iBytes);
  401. if (iBytes <= 0)
  402. {
  403. break;
  404. }
  405. }
  406. output.Close();
  407. if (socketData.Connected)
  408. {
  409. socketData.Close();
  410. }
  411. if (!(iReplyCode == 226 || iReplyCode == 250))
  412. {
  413. ReadReply();
  414. if (!(iReplyCode == 226 || iReplyCode == 250))
  415. {
  416. throw new IOException(strReply.Substring(4));
  417. }
  418. }
  419. }
  420. }
  421. /// <summary>
  422. /// 下载一个文件
  423. /// </summary>
  424. /// <param name="strRemoteFileName">要下载的文件名</param>
  425. /// <param name="strFolder">本地目录(不得以\结束)</param>
  426. /// <param name="strLocalFileName">保存在本地时的文件名</param>
  427. public void DownloadFile(string strRemoteFileName, string strFolder, string strLocalFileName)
  428. {
  429. if (!bConnected)
  430. {
  431. Connect();
  432. }
  433. SetTransferType(TransferType.Binary);
  434. if (strLocalFileName.Equals(""))
  435. {
  436. strLocalFileName = strRemoteFileName;
  437. }
  438. if (!File.Exists(strLocalFileName))
  439. {
  440. Stream st = File.Create(strLocalFileName);
  441. st.Close();
  442. }
  443. FileStream output = new
  444. FileStream(strFolder + "\\" + strLocalFileName, FileMode.Create);
  445. Socket socketData = CreateDataSocket();
  446. SendCommand("RETR " + strRemoteFileName);
  447. if (!(iReplyCode == 150 || iReplyCode == 125
  448. || iReplyCode == 226 || iReplyCode == 250))
  449. {
  450. throw new IOException(strReply.Substring(4));
  451. }
  452. while (true)
  453. {
  454. int iBytes = socketData.Receive(buffer, buffer.Length, 0);
  455. output.Write(buffer, 0, iBytes);
  456. if (iBytes <= 0)
  457. {
  458. break;
  459. }
  460. }
  461. output.Close();
  462. if (socketData.Connected)
  463. {
  464. socketData.Close();
  465. }
  466. if (!(iReplyCode == 226 || iReplyCode == 250))
  467. {
  468. ReadReply();
  469. if (!(iReplyCode == 226 || iReplyCode == 250))
  470. {
  471. throw new IOException(strReply.Substring(4));
  472. }
  473. }
  474. }
  475. /// <summary>
  476. /// 下载一个文件(断点续传)
  477. /// </summary>
  478. /// <param name="strRemoteFileName">要下载的文件名</param>
  479. /// <param name="strFolder">本地目录(不得以\结束)</param>
  480. /// <param name="strLocalFileName">保存在本地时的文件名</param>
  481. /// <param name="size">已下载文件流长度</param>
  482. public void DownloadBrokenFile(string strRemoteFileName, string strFolder, string strLocalFileName, long size)
  483. {
  484. if (!bConnected)
  485. {
  486. Connect();
  487. }
  488. SetTransferType(TransferType.Binary);
  489. FileStream output = new
  490. FileStream(strFolder + "\\" + strLocalFileName, FileMode.Append);
  491. Socket socketData = CreateDataSocket();
  492. SendCommand("REST " + size.ToString());
  493. SendCommand("RETR " + strRemoteFileName);
  494. if (!(iReplyCode == 150 || iReplyCode == 125
  495. || iReplyCode == 226 || iReplyCode == 250))
  496. {
  497. throw new IOException(strReply.Substring(4));
  498. }
  499. while (true)
  500. {
  501. int iBytes = socketData.Receive(buffer, buffer.Length, 0);
  502. output.Write(buffer, 0, iBytes);
  503. if (iBytes <= 0)
  504. {
  505. break;
  506. }
  507. }
  508. output.Close();
  509. if (socketData.Connected)
  510. {
  511. socketData.Close();
  512. }
  513. if (!(iReplyCode == 226 || iReplyCode == 250))
  514. {
  515. ReadReply();
  516. if (!(iReplyCode == 226 || iReplyCode == 250))
  517. {
  518. throw new IOException(strReply.Substring(4));
  519. }
  520. }
  521. }
  522. /// <summary>
  523. /// 上传一批文件
  524. /// </summary>
  525. /// <param name="strFolder">本地目录(不得以\结束)</param>
  526. /// <param name="strFileNameMask">文件名匹配字符(可以包含*和?)</param>
  527. public void Upload(string strFolder, string strFileNameMask)
  528. {
  529. string[] strFiles = Directory.GetFiles(strFolder, strFileNameMask);
  530. foreach (string strFile in strFiles)
  531. {
  532. //strFile是完整的文件名(包含路径)
  533. Upload(strFile);
  534. }
  535. }
  536. /// <summary>
  537. /// 上传一个文件
  538. /// </summary>
  539. /// <param name="strFileName">本地文件名</param>
  540. public void Upload(string strFileName)
  541. {
  542. if (!bConnected)
  543. {
  544. Connect();
  545. }
  546. Socket socketData = CreateDataSocket();
  547. SendCommand("STOR " + Path.GetFileName(strFileName));
  548. if (!(iReplyCode == 125 || iReplyCode == 150))
  549. {
  550. throw new IOException(strReply.Substring(4));
  551. }
  552. FileStream input = new
  553. FileStream(strFileName, FileMode.Open);
  554. int iBytes = 0;
  555. while ((iBytes = input.Read(buffer, 0, buffer.Length)) > 0)
  556. {
  557. socketData.Send(buffer, iBytes, 0);
  558. }
  559. input.Close();
  560. if (socketData.Connected)
  561. {
  562. socketData.Close();
  563. }
  564. if (!(iReplyCode == 226 || iReplyCode == 250))
  565. {
  566. ReadReply();
  567. if (!(iReplyCode == 226 || iReplyCode == 250))
  568. {
  569. throw new IOException(strReply.Substring(4));
  570. }
  571. }
  572. }
  573. #endregion
  574. #region 目录操作
  575. /// <summary>
  576. /// 创建目录
  577. /// </summary>
  578. /// <param name="strDirName">目录名</param>
  579. public void MkDir(string strDirName)
  580. {
  581. if (!bConnected)
  582. {
  583. Connect();
  584. }
  585. SendCommand("MKD " + strDirName);
  586. if (iReplyCode != 257)
  587. {
  588. throw new IOException(strReply.Substring(4));
  589. }
  590. }
  591. /// <summary>
  592. /// 删除目录
  593. /// </summary>
  594. /// <param name="strDirName">目录名</param>
  595. public void RmDir(string strDirName)
  596. {
  597. if (!bConnected)
  598. {
  599. Connect();
  600. }
  601. SendCommand("RMD " + strDirName);
  602. if (iReplyCode != 250)
  603. {
  604. throw new IOException(strReply.Substring(4));
  605. }
  606. }
  607. /// <summary>
  608. /// 改变目录
  609. /// </summary>
  610. /// <param name="strDirName">新的工作目录名</param>
  611. public void ChDir(string strDirName)
  612. {
  613. if (strDirName.Equals(".") || strDirName.Equals(""))
  614. {
  615. return;
  616. }
  617. if (!bConnected)
  618. {
  619. Connect();
  620. }
  621. SendCommand("CWD " + strDirName);
  622. if (iReplyCode != 250)
  623. {
  624. throw new IOException(strReply.Substring(4));
  625. }
  626. this.remoteFilePath = strDirName;
  627. }
  628. #endregion
  629. #region 内部变量
  630. /// <summary>
  631. /// 服务器返回的应答信息(包含应答码)
  632. /// </summary>
  633. private string strMsg;
  634. /// <summary>
  635. /// 服务器返回的应答信息(包含应答码)
  636. /// </summary>
  637. private string strReply;
  638. /// <summary>
  639. /// 服务器返回的应答码
  640. /// </summary>
  641. private int iReplyCode;
  642. /// <summary>
  643. /// 进行控制连接的socket
  644. /// </summary>
  645. private Socket socketControl;
  646. /// <summary>
  647. /// 传输模式
  648. /// </summary>
  649. private TransferType trType;
  650. /// <summary>
  651. /// 接收和发送数据的缓冲区
  652. /// </summary>
  653. private static int BLOCK_SIZE = 512;
  654. Byte[] buffer = new Byte[BLOCK_SIZE];
  655. /// <summary>
  656. /// 编码方式(为防止出现中文乱码采用 GB2312编码方式)
  657. /// </summary>
  658. Encoding GB2312 = Encoding.GetEncoding("gb2312");
  659. #endregion
  660. #region 内部函数
  661. /// <summary>
  662. /// 将一行应答字符串记录在strReply和strMsg
  663. /// 应答码记录在iReplyCode
  664. /// </summary>
  665. private void ReadReply()
  666. {
  667. strMsg = "";
  668. strReply = ReadLine();
  669. iReplyCode = Int32.Parse(strReply.Substring(0, 3));
  670. }
  671. /// <summary>
  672. /// 建立进行数据连接的socket
  673. /// </summary>
  674. /// <returns>数据连接socket</returns>
  675. private Socket CreateDataSocket()
  676. {
  677. SendCommand("PASV");
  678. if (iReplyCode != 227)
  679. {
  680. throw new IOException(strReply.Substring(4));
  681. }
  682. int index1 = strReply.IndexOf('(');
  683. int index2 = strReply.IndexOf(')');
  684. string ipData =
  685. strReply.Substring(index1 + 1, index2 - index1 - 1);
  686. int[] parts = new int[6];
  687. int len = ipData.Length;
  688. int partCount = 0;
  689. string buf = "";
  690. for (int i = 0; i < len && partCount <= 6; i++)
  691. {
  692. char ch = Char.Parse(ipData.Substring(i, 1));
  693. if (Char.IsDigit(ch))
  694. buf += ch;
  695. else if (ch != ',')
  696. {
  697. throw new IOException("Malformed PASV strReply: " +
  698. strReply);
  699. }
  700. if (ch == ',' || i + 1 == len)
  701. {
  702. try
  703. {
  704. parts[partCount++] = Int32.Parse(buf);
  705. buf = "";
  706. }
  707. catch (Exception)
  708. {
  709. throw new IOException("Malformed PASV strReply: " +
  710. strReply);
  711. }
  712. }
  713. }
  714. string ipAddress = parts[0] + "." + parts[1] + "." +
  715. parts[2] + "." + parts[3];
  716. int port = (parts[4] << 8) + parts[5];
  717. Socket s = new
  718. Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  719. IPEndPoint ep = new
  720. IPEndPoint(IPAddress.Parse(ipAddress), port);
  721. try
  722. {
  723. s.Connect(ep);
  724. }
  725. catch (Exception)
  726. {
  727. throw new IOException("Can't connect to remote server");
  728. }
  729. return s;
  730. }
  731. /// <summary>
  732. /// 关闭socket连接(用于登录以前)
  733. /// </summary>
  734. private void CloseSocketConnect()
  735. {
  736. if (socketControl != null)
  737. {
  738. socketControl.Close();
  739. socketControl = null;
  740. }
  741. bConnected = false;
  742. }
  743. /// <summary>
  744. /// 读取Socket返回的所有字符串
  745. /// </summary>
  746. /// <returns>包含应答码的字符串行</returns>
  747. private string ReadLine()
  748. {
  749. while (true)
  750. {
  751. int iBytes = socketControl.Receive(buffer, buffer.Length, 0);
  752. strMsg += GB2312.GetString(buffer, 0, iBytes);
  753. if (iBytes < buffer.Length)
  754. {
  755. break;
  756. }
  757. }
  758. char[] seperator = { '\n' };
  759. string[] mess = strMsg.Split(seperator);
  760. if (strMsg.Length > 2)
  761. {
  762. strMsg = mess[mess.Length - 2];
  763. //seperator[0]是10,换行符是由13和0组成的,分隔后10后面虽没有字符串,
  764. //但也会分配为空字符串给后面(也是最后一个)字符串数组,
  765. //所以最后一个mess是没用的空字符串
  766. //但为什么不直接取mess[0],因为只有最后一行字符串应答码与信息之间有空格
  767. }
  768. else
  769. {
  770. strMsg = mess[0];
  771. }
  772. if (!strMsg.Substring(3, 1).Equals(" "))//返回字符串正确的是以应答码(如220开头,后面接一空格,再接问候字符串)
  773. {
  774. return ReadLine();
  775. }
  776. return strMsg;
  777. }
  778. /// <summary>
  779. /// 发送命令并获取应答码和最后一行应答字符串
  780. /// </summary>
  781. /// <param name="strCommand">命令</param>
  782. private void SendCommand(String strCommand)
  783. {
  784. Byte[] cmdBytes =
  785. GB2312.GetBytes((strCommand + "\r\n").ToCharArray());
  786. socketControl.Send(cmdBytes, cmdBytes.Length, 0);
  787. ReadReply();
  788. }
  789. #endregion
  790. }
  791. }

该代码上传不支持断点续传,不支持匿名下载,有该需求的朋友可以参考:
点击打开链接


相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载