diff --git a/FastDFS/Common/FDFSRequest.cs b/FastDFS/Common/FDFSRequest.cs
index 2ef1ff4..27e0e60 100644
--- a/FastDFS/Common/FDFSRequest.cs
+++ b/FastDFS/Common/FDFSRequest.cs
@@ -1,102 +1,102 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.IO;
-using System.Collections;
-using System.Net;
-using System.Net.Sockets;
-
-namespace FastDFS.Client
-{
- public class FDFSRequest
- {
- private FDFSHeader _header;
- public FDFSHeader Header
- {
- set { _header = value; }
- get { return _header; }
- }
- private byte[] _body;
- public byte[] Body
- {
- set { _body = value; }
- get { return _body; }
- }
- private Connection _connection;
- public Connection Connection
- {
- get { return _connection; }
- set { this._connection = value; }
- }
-
- public FDFSRequest()
- {
-
- }
-
- public byte[] ToByteArray()
- {
- throw new NotImplementedException();
- }
-
- public virtual FDFSRequest GetRequest(params object[] paramList)
- {
- throw new NotImplementedException();
- }
-
-
- protected virtual void SendRequest(Stream outputStream)
- {
- byte[] headerBuffer = this._header.ToByte();
- outputStream.Write(headerBuffer, 0, headerBuffer.Length);
- outputStream.Write(this._body, 0, this._body.Length);
- }
-
-
- public void GetResponse()
- {
- GetResponse(null);
- }
-
- public virtual void GetResponse(FDFSResponse response)
- {
- if(this._connection == null)
- this._connection = ConnectionManager.GetTrackerConnection();
- _connection.Open();
- try
- {
- NetworkStream stream = this._connection.GetStream();
- this.SendRequest(stream);
-
-
- FDFSHeader header = new FDFSHeader(stream);
- if (header.Status != 0)
- throw new FDFSException(string.Format("Get Response Error,Error Code:{0}", header.Status));
-
- if (response != null)
- response.ReceiveResponse(stream, header.Length);
- _connection.Close();
- }
- catch(Exception ex)
- {
- _connection.Release();
- throw ex;//可以看Storage节点的log看
- //22 -〉下载字节数超过文件长度 invalid download file bytes: 10 > file remain bytes: 4
- // -> 或者 pkg length is not correct
- //2 -〉没有此文件 error info: No such file or directory.
- }
- }
- }
-
- public class FDFSResponse
- {
- public virtual void ReceiveResponse(Stream stream, long length) {
- byte[] content = new byte[length];
- stream.Read(content, 0, (int)length);
- LoadContent(content);
- }
- protected virtual void LoadContent(byte[] content)
- {
- }
- }
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+using System.Collections;
+using System.Net;
+using System.Net.Sockets;
+
+namespace FastDFS.Client
+{
+ public class FDFSRequest
+ {
+ private FDFSHeader _header;
+ public FDFSHeader Header
+ {
+ set { _header = value; }
+ get { return _header; }
+ }
+ private byte[] _body;
+ public byte[] Body
+ {
+ set { _body = value; }
+ get { return _body; }
+ }
+ private Connection _connection;
+ public Connection Connection
+ {
+ get { return _connection; }
+ set { this._connection = value; }
+ }
+
+ public FDFSRequest()
+ {
+
+ }
+
+ public byte[] ToByteArray()
+ {
+ throw new NotImplementedException();
+ }
+
+ public virtual FDFSRequest GetRequest(params object[] paramList)
+ {
+ throw new NotImplementedException();
+ }
+
+
+ protected virtual void SendRequest(Stream outputStream)
+ {
+ byte[] headerBuffer = this._header.ToByte();
+ outputStream.Write(headerBuffer, 0, headerBuffer.Length);
+ outputStream.Write(this._body, 0, this._body.Length);
+ }
+
+
+ public void GetResponse()
+ {
+ GetResponse(null);
+ }
+
+ public virtual void GetResponse(FDFSResponse response)
+ {
+ if(this._connection == null)
+ this._connection = ConnectionManager.GetTrackerConnection();
+ _connection.Open();
+ try
+ {
+ NetworkStream stream = this._connection.GetStream();
+ this.SendRequest(stream);
+
+
+ FDFSHeader header = new FDFSHeader(stream);
+ if (header.Status != 0)
+ throw new FDFSException(string.Format("Get Response Error,Error Code:{0}", header.Status));
+
+ if (response != null)
+ response.ReceiveResponse(stream, header.Length);
+ _connection.Close();
+ }
+ catch(Exception ex)
+ {
+ _connection.Release();
+ throw ex;//可以看Storage节点的log看
+ //22 -〉下载字节数超过文件长度 invalid download file bytes: 10 > file remain bytes: 4
+ // -> 或者 pkg length is not correct
+ //2 -〉没有此文件 error info: No such file or directory.
+ }
+ }
+ }
+
+ public class FDFSResponse
+ {
+ public virtual void ReceiveResponse(Stream stream, long length) {
+ byte[] content = new byte[length];
+ stream.Read(content, 0, (int)length);
+ LoadContent(content);
+ }
+ protected virtual void LoadContent(byte[] content)
+ {
+ }
+ }
}
\ No newline at end of file
diff --git a/FastDFS/Common/Util.cs b/FastDFS/Common/Util.cs
index 91e9306..7d26883 100644
--- a/FastDFS/Common/Util.cs
+++ b/FastDFS/Common/Util.cs
@@ -1,130 +1,130 @@
-/****************************************************************************************************************
-* *
-* Copyright (C) *
-* *
-* *
-* *
-* Author:
-* add md5,GetToken Function by G小星星 *
-* *
-****************************************************************************************************************/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Security.Cryptography;
-
-namespace FastDFS.Client
-{
- public class Util
- {
- ///
- /// Convert Long to byte[]
- ///
- ///
- ///
- public static byte[] LongToBuffer(long l)
- {
- byte[] buffer = new byte[8];
- buffer[0] = (byte)((l >> 56) & 0xFF);
- buffer[1] = (byte)((l >> 48) & 0xFF);
- buffer[2] = (byte)((l >> 40) & 0xFF);
- buffer[3] = (byte)((l >> 32) & 0xFF);
- buffer[4] = (byte)((l >> 24) & 0xFF);
- buffer[5] = (byte)((l >> 16) & 0xFF);
- buffer[6] = (byte)((l >> 8) & 0xFF);
- buffer[7] = (byte)(l & 0xFF);
-
- return buffer;
- }
- ///
- /// Convert byte[] to Long
- ///
- ///
- ///
- ///
- public static long BufferToLong(byte[] buffer, int offset)
- {
- return (((long)(buffer[offset] >= 0 ? buffer[offset] : 256 + buffer[offset])) << 56) |
- (((long)(buffer[offset + 1] >= 0 ? buffer[offset + 1] : 256 + buffer[offset + 1])) << 48) |
- (((long)(buffer[offset + 2] >= 0 ? buffer[offset + 2] : 256 + buffer[offset + 2])) << 40) |
- (((long)(buffer[offset + 3] >= 0 ? buffer[offset + 3] : 256 + buffer[offset + 3])) << 32) |
- (((long)(buffer[offset + 4] >= 0 ? buffer[offset + 4] : 256 + buffer[offset + 4])) << 24) |
- (((long)(buffer[offset + 5] >= 0 ? buffer[offset + 5] : 256 + buffer[offset + 5])) << 16) |
- (((long)(buffer[offset + 6] >= 0 ? buffer[offset + 6] : 256 + buffer[offset + 6])) << 8) |
- ((buffer[offset + 7] >= 0 ? buffer[offset + 7] : 256 + buffer[offset + 7]));
- }
-
- public static string ByteToString(byte[] input)
- {
- char[] chars = FDFSConfig.Charset.GetChars(input);
- string result = new string(chars, 0, chars.Length);
- return result;
- }
-
- public static string ByteToString(byte[] input, int startIndex, int count)
- {
- char[] chars = FDFSConfig.Charset.GetChars(input, startIndex, count);
- string result = new string(chars, 0, chars.Length);
- return result;
- }
-
- public static byte[] StringToByte(string input)
- {
- return FDFSConfig.Charset.GetBytes(input);
- }
-
- public static byte[] CreateGroupNameBuffer(string groupName)
- {
- byte[] groupBytes = new byte[Consts.FDFS_GROUP_NAME_MAX_LEN];
- byte[] bytes = Util.StringToByte(groupName);
- Array.Copy(bytes, groupBytes, Math.Min(groupBytes.Length, bytes.Length));
- return groupBytes;
- }
-
- ///
- /// get token for file URL
- ///
- /// file_id the file id return by FastDFS server
- /// ts unix timestamp, unit: second
- /// secret_key the secret key
- /// token string
-
- public static string GetToken(string file_id, int ts, string secret_key)
- {
- byte[] bsFileId = StringToByte(file_id);
- byte[] bsKey = StringToByte(secret_key);
- byte[] bsTimestamp = StringToByte(ts.ToString());
-
- byte[] buff = new byte[bsFileId.Length + bsKey.Length + bsTimestamp.Length];
- Array.Copy(bsFileId, 0, buff, 0, bsFileId.Length);
- Array.Copy(bsKey, 0, buff, bsFileId.Length, bsKey.Length);
- Array.Copy(bsTimestamp, 0, buff, bsFileId.Length + bsKey.Length, bsTimestamp.Length);
-
- return md5(buff);
- }
- ///
- /// md5 function
- ///
- /// source the input buffer
- /// md5 string
- public static string md5(byte[] source)
- {
-
- string pwd = "";
- MD5 md5 = MD5.Create();//实例化一个md5对像
- // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择
- byte[] s = md5.ComputeHash(source);
- // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
- for (int i = 0; i < s.Length; i++)
- {
- // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
- pwd = pwd + s[i].ToString("X2");
- int len = pwd.Length;
-
- }
- return pwd.ToLower();
- }
-
- }
-}
-
+/****************************************************************************************************************
+* *
+* Copyright (C) *
+* *
+* *
+* *
+* Author:
+* add md5,GetToken Function by G小星星 *
+* *
+****************************************************************************************************************/
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Security.Cryptography;
+
+namespace FastDFS.Client
+{
+ public class Util
+ {
+ ///
+ /// Convert Long to byte[]
+ ///
+ ///
+ ///
+ public static byte[] LongToBuffer(long l)
+ {
+ byte[] buffer = new byte[8];
+ buffer[0] = (byte)((l >> 56) & 0xFF);
+ buffer[1] = (byte)((l >> 48) & 0xFF);
+ buffer[2] = (byte)((l >> 40) & 0xFF);
+ buffer[3] = (byte)((l >> 32) & 0xFF);
+ buffer[4] = (byte)((l >> 24) & 0xFF);
+ buffer[5] = (byte)((l >> 16) & 0xFF);
+ buffer[6] = (byte)((l >> 8) & 0xFF);
+ buffer[7] = (byte)(l & 0xFF);
+
+ return buffer;
+ }
+ ///
+ /// Convert byte[] to Long
+ ///
+ ///
+ ///
+ ///
+ public static long BufferToLong(byte[] buffer, int offset)
+ {
+ return (((long)(buffer[offset] >= 0 ? buffer[offset] : 256 + buffer[offset])) << 56) |
+ (((long)(buffer[offset + 1] >= 0 ? buffer[offset + 1] : 256 + buffer[offset + 1])) << 48) |
+ (((long)(buffer[offset + 2] >= 0 ? buffer[offset + 2] : 256 + buffer[offset + 2])) << 40) |
+ (((long)(buffer[offset + 3] >= 0 ? buffer[offset + 3] : 256 + buffer[offset + 3])) << 32) |
+ (((long)(buffer[offset + 4] >= 0 ? buffer[offset + 4] : 256 + buffer[offset + 4])) << 24) |
+ (((long)(buffer[offset + 5] >= 0 ? buffer[offset + 5] : 256 + buffer[offset + 5])) << 16) |
+ (((long)(buffer[offset + 6] >= 0 ? buffer[offset + 6] : 256 + buffer[offset + 6])) << 8) |
+ ((buffer[offset + 7] >= 0 ? buffer[offset + 7] : 256 + buffer[offset + 7]));
+ }
+
+ public static string ByteToString(byte[] input)
+ {
+ char[] chars = FDFSConfig.Charset.GetChars(input);
+ string result = new string(chars, 0, chars.Length);
+ return result;
+ }
+
+ public static string ByteToString(byte[] input, int startIndex, int count)
+ {
+ char[] chars = FDFSConfig.Charset.GetChars(input, startIndex, count);
+ string result = new string(chars, 0, chars.Length);
+ return result;
+ }
+
+ public static byte[] StringToByte(string input)
+ {
+ return FDFSConfig.Charset.GetBytes(input);
+ }
+
+ public static byte[] CreateGroupNameBuffer(string groupName)
+ {
+ byte[] groupBytes = new byte[Consts.FDFS_GROUP_NAME_MAX_LEN];
+ byte[] bytes = Util.StringToByte(groupName);
+ Array.Copy(bytes, groupBytes, Math.Min(groupBytes.Length, bytes.Length));
+ return groupBytes;
+ }
+
+ ///
+ /// get token for file URL
+ ///
+ /// file_id the file id return by FastDFS server
+ /// ts unix timestamp, unit: second
+ /// secret_key the secret key
+ /// token string
+
+ public static string GetToken(string file_id, int ts, string secret_key)
+ {
+ byte[] bsFileId = StringToByte(file_id);
+ byte[] bsKey = StringToByte(secret_key);
+ byte[] bsTimestamp = StringToByte(ts.ToString());
+
+ byte[] buff = new byte[bsFileId.Length + bsKey.Length + bsTimestamp.Length];
+ Array.Copy(bsFileId, 0, buff, 0, bsFileId.Length);
+ Array.Copy(bsKey, 0, buff, bsFileId.Length, bsKey.Length);
+ Array.Copy(bsTimestamp, 0, buff, bsFileId.Length + bsKey.Length, bsTimestamp.Length);
+
+ return md5(buff);
+ }
+ ///
+ /// md5 function
+ ///
+ /// source the input buffer
+ /// md5 string
+ public static string md5(byte[] source)
+ {
+
+ string pwd = "";
+ MD5 md5 = MD5.Create();//实例化一个md5对像
+ // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择
+ byte[] s = md5.ComputeHash(source);
+ // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
+ for (int i = 0; i < s.Length; i++)
+ {
+ // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
+ pwd = pwd + s[i].ToString("X2");
+ int len = pwd.Length;
+
+ }
+ return pwd.ToLower();
+ }
+
+ }
+}
+
diff --git a/FastDFS/FastDFSClient.cs b/FastDFS/FastDFSClient.cs
index a5d7a11..45db53e 100644
--- a/FastDFS/FastDFSClient.cs
+++ b/FastDFS/FastDFSClient.cs
@@ -1,227 +1,227 @@
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Net;
-using System.Net.Sockets;
-namespace FastDFS.Client
-{
- public class FastDFSClient
- {
- ///
- /// 获取存储节点
- ///
- /// 组名
- /// 存储节点实体类
- public static StorageNode GetStorageNode(string groupName)
- {
- FDFSRequest trackerRequest = QUERY_STORE_WITH_GROUP_ONE.Instance.GetRequest(groupName);
- QUERY_STORE_WITH_GROUP_ONE.Response trackerResponse = new QUERY_STORE_WITH_GROUP_ONE.Response();
- trackerRequest.GetResponse(trackerResponse);
- IPEndPoint storeEndPoint = new IPEndPoint(IPAddress.Parse(trackerResponse.IPStr), trackerResponse.Port);
- StorageNode result = new StorageNode();
- result.GroupName = trackerResponse.GroupName;
- result.EndPoint = storeEndPoint;
- result.StorePathIndex = trackerResponse.StorePathIndex;
- return result;
- }
- public static StorageNode QueryStorageNodeForFile(string groupName, string fileid)
- {
- FDFSRequest trackerRequest = QUERY_FETCH_ONE.Instance.GetRequest(groupName, fileid);
- QUERY_FETCH_ONE.Response trackerResponse = new QUERY_FETCH_ONE.Response();
- trackerRequest.GetResponse(trackerResponse);
- IPEndPoint storeEndPoint = new IPEndPoint(IPAddress.Parse(trackerResponse.IPStr), trackerResponse.Port);
- StorageNode result = new StorageNode();
- result.GroupName = trackerResponse.GroupName;
- result.EndPoint = storeEndPoint;
- result.StorePathIndex = 0;
- return result;
- }
- public static StorageNode[] QueryStorageNodesForFile(string groupName, string fileid)
- {
- FDFSRequest trackerRequest = QUERY_FETCH_ALL.Instance.GetRequest(groupName, fileid);
- QUERY_FETCH_ALL.Response trackerResponse = new QUERY_FETCH_ALL.Response();
- trackerRequest.GetResponse(trackerResponse);
-
- List storageNodes = new List();
- foreach (string IPStr in trackerResponse.IPStrs)
- {
- StorageNode storage = new StorageNode();
- storage.GroupName = trackerResponse.GroupName;
- storage.EndPoint = new IPEndPoint(IPAddress.Parse(IPStr), trackerResponse.Port);
- storage.StorePathIndex = 0;
- storageNodes.Add(storage);
- }
- return storageNodes.ToArray();
- }
- ///
- /// 上传文件
- ///
- /// GetStorageNode方法返回的存储节点
- /// 文件内容
- /// 文件扩展名(注意:不包含".")
- /// 文件名
- public static string UploadFile(StorageNode storageNode,byte[] contentByte,string fileExt)
- {
- FDFSRequest storageRequest = UPLOAD_FILE.Instance.GetRequest(storageNode.EndPoint, storageNode.StorePathIndex, contentByte.Length, fileExt, contentByte);
- UPLOAD_FILE.Response storageResponse = new UPLOAD_FILE.Response();
- storageRequest.GetResponse(storageResponse);
- return storageResponse.FileName;
- }
-
- public static string UploadFileByName(StorageNode storageNode, string filename)
- {
- using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
- {
- string extension = Path.GetExtension(filename).Substring(1);
- FDFSRequest storageRequest = UPLOAD_FILE.Instance.GetRequest(storageNode.EndPoint, storageNode.StorePathIndex, fs.Length, extension, fs);
- UPLOAD_FILE.Response storageResponse = new UPLOAD_FILE.Response();
- storageRequest.GetResponse(storageResponse);
- return storageResponse.FileName;
- }
- }
-
- ///
- /// 上传从文件
- ///
- /// GetStorageNode方法返回的存储节点
- /// 文件内容
- /// 主文件名
- /// 从文件后缀
- /// 文件扩展名(注意:不包含".")
- /// 文件名
- public static string UploadSlaveFile(string groupName, byte[] contentByte, string master_filename, string prefix_name, string fileExt)
- {
- FDFSRequest trackerRequest = QUERY_UPDATE.Instance.GetRequest(groupName, master_filename);
- QUERY_UPDATE.Response trackerResponse = new QUERY_UPDATE.Response();
- trackerRequest.GetResponse(trackerResponse);
- IPEndPoint storeEndPoint = new IPEndPoint(IPAddress.Parse(trackerResponse.IPStr), trackerResponse.Port);
-
- FDFSRequest storageRequest = UPLOAD_SLAVE_FILE.Instance.GetRequest(storeEndPoint, contentByte.Length, master_filename, prefix_name, fileExt, contentByte);
- UPLOAD_FILE.Response storageResponse = new UPLOAD_FILE.Response();
- storageRequest.GetResponse(storageResponse);
- return storageResponse.FileName;
- }
-
-
- ///
- /// 上传可以Append的文件
- ///
- /// GetStorageNode方法返回的存储节点
- /// 文件内容
- /// 文件扩展名(注意:不包含".")
- /// 文件名
- public static string UploadAppenderFile(StorageNode storageNode, byte[] contentByte, string fileExt)
- {
- FDFSRequest storageRequest = UPLOAD_APPEND_FILE.Instance.GetRequest(storageNode.EndPoint, storageNode.StorePathIndex, contentByte.Length, fileExt, contentByte);
- UPLOAD_APPEND_FILE.Response storageResponse = new UPLOAD_APPEND_FILE.Response();
- storageRequest.GetResponse(storageResponse);
- return storageResponse.FileName;
- }
- ///
- /// 附加文件
- ///
- /// 组名
- /// 文件名
- /// 文件内容
- public static void AppendFile(string groupName,string fileName, byte[] contentByte)
- {
- FDFSRequest trackerRequest = QUERY_UPDATE.Instance.GetRequest(groupName, fileName);
- QUERY_UPDATE.Response trackerResponse = new QUERY_UPDATE.Response();
- trackerRequest.GetResponse(trackerResponse);
- IPEndPoint storeEndPoint = new IPEndPoint(IPAddress.Parse(trackerResponse.IPStr), trackerResponse.Port);
-
- FDFSRequest storageRequest = APPEND_FILE.Instance.GetRequest(storeEndPoint, fileName, contentByte);
- storageRequest.GetResponse();
- }
- ///
- /// 删除文件
- ///
- /// 组名
- /// 文件名
- public static void RemoveFile(string groupName,string fileName)
- {
- FDFSRequest trackerRequest = QUERY_UPDATE.Instance.GetRequest(groupName, fileName);
- QUERY_UPDATE.Response trackerResponse = new QUERY_UPDATE.Response();
- trackerRequest.GetResponse(trackerResponse);
- IPEndPoint storeEndPoint = new IPEndPoint(IPAddress.Parse(trackerResponse.IPStr), trackerResponse.Port);
- FDFSRequest storageRequest = DELETE_FILE.Instance.GetRequest(storeEndPoint, groupName, fileName);
- storageRequest.GetResponse();
- }
- ///
- /// 下载文件
- ///
- /// GetStorageNode方法返回的存储节点
- /// 文件名
- /// 文件内容
- public static byte[] DownloadFile(StorageNode storageNode,string fileName)
- {
- FDFSRequest storageRequest = DOWNLOAD_FILE.Instance.GetRequest(storageNode.EndPoint, 0L, 0L, storageNode.GroupName, fileName);
- DOWNLOAD_FILE.Response storageResponse = new DOWNLOAD_FILE.Response();
- storageRequest.GetResponse(storageResponse);
- return storageResponse.Content;
- }
- ///
- /// 增量下载文件
- ///
- /// GetStorageNode方法返回的存储节点
- /// 文件名
- /// 从文件起始点的偏移量
- /// 要读取的字节数
- /// 文件内容
- public static byte[] DownloadFile(StorageNode storageNode, string fileName, long offset, long length)
- {
- FDFSRequest storageRequest = DOWNLOAD_FILE.Instance.GetRequest(storageNode.EndPoint, offset, length, storageNode.GroupName, fileName);
- DOWNLOAD_FILE.Response storageResponse = new DOWNLOAD_FILE.Response();
- storageRequest.GetResponse(storageResponse);
- return storageResponse.Content;
- }
-
- public static string DownloadFileEx(StorageNode storageNode, string filename, string destDir, string destFileName = null)
- {
- string fullPath = null;
- if (destFileName == null)
- {
- IDictionary metaData = GetMetaData(storageNode, filename);
- destFileName = metaData["Name"] + Path.GetExtension(filename);
- }
- fullPath = Path.Combine(destDir, destFileName);
- FDFSRequest storageRequest = DOWNLOAD_FILE.Instance.GetRequest(storageNode.EndPoint, 0L, 0L, storageNode.GroupName, filename);
- DOWNLOAD_FILE.ResponseEx storageResponse = new DOWNLOAD_FILE.ResponseEx(fullPath);
- storageRequest.GetResponse(storageResponse);
- return storageResponse.FullPath;
- }
-
- ///
- /// 获取文件信息
- ///
- /// GetStorageNode方法返回的存储节点
- /// 文件名
- ///
- public static FDFSFileInfo GetFileInfo(StorageNode storageNode, string fileName)
- {
- FDFSRequest storageRequest = QUERY_FILE_INFO.Instance.GetRequest(storageNode.EndPoint, storageNode.GroupName, fileName);
- FDFSFileInfo result = new FDFSFileInfo();
- storageRequest.GetResponse(result);
- return result;
- }
-
-
- public static void SetMetaData(StorageNode storageNode, string fileName, IDictionary metadata, MetaDataOption option = MetaDataOption.Overwrite)
- {
- FDFSRequest storageRequest = SET_METADATA.Instance.GetRequest(storageNode.EndPoint, storageNode.GroupName, fileName, metadata, option);
- storageRequest.GetResponse(); // no response body
- }
-
- public static IDictionary GetMetaData(StorageNode storageNode, string fileName)
- {
- FDFSRequest storageRequest = GET_METADATA.Instance.GetRequest(storageNode.EndPoint, storageNode.GroupName, fileName);
- GET_METADATA.Response storageResponse = new GET_METADATA.Response();
- storageRequest.GetResponse(storageResponse);
- return storageResponse.MetaData;
- }
-
-
- }
-}
+using System;
+using System.IO;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Net;
+using System.Net.Sockets;
+namespace FastDFS.Client
+{
+ public class FastDFSClient
+ {
+ ///
+ /// 获取存储节点
+ ///
+ /// 组名
+ /// 存储节点实体类
+ public static StorageNode GetStorageNode(string groupName)
+ {
+ FDFSRequest trackerRequest = QUERY_STORE_WITH_GROUP_ONE.Instance.GetRequest(groupName);
+ QUERY_STORE_WITH_GROUP_ONE.Response trackerResponse = new QUERY_STORE_WITH_GROUP_ONE.Response();
+ trackerRequest.GetResponse(trackerResponse);
+ IPEndPoint storeEndPoint = new IPEndPoint(IPAddress.Parse(trackerResponse.IPStr), trackerResponse.Port);
+ StorageNode result = new StorageNode();
+ result.GroupName = trackerResponse.GroupName;
+ result.EndPoint = storeEndPoint;
+ result.StorePathIndex = trackerResponse.StorePathIndex;
+ return result;
+ }
+ public static StorageNode QueryStorageNodeForFile(string groupName, string fileid)
+ {
+ FDFSRequest trackerRequest = QUERY_FETCH_ONE.Instance.GetRequest(groupName, fileid);
+ QUERY_FETCH_ONE.Response trackerResponse = new QUERY_FETCH_ONE.Response();
+ trackerRequest.GetResponse(trackerResponse);
+ IPEndPoint storeEndPoint = new IPEndPoint(IPAddress.Parse(trackerResponse.IPStr), trackerResponse.Port);
+ StorageNode result = new StorageNode();
+ result.GroupName = trackerResponse.GroupName;
+ result.EndPoint = storeEndPoint;
+ result.StorePathIndex = 0;
+ return result;
+ }
+ public static StorageNode[] QueryStorageNodesForFile(string groupName, string fileid)
+ {
+ FDFSRequest trackerRequest = QUERY_FETCH_ALL.Instance.GetRequest(groupName, fileid);
+ QUERY_FETCH_ALL.Response trackerResponse = new QUERY_FETCH_ALL.Response();
+ trackerRequest.GetResponse(trackerResponse);
+
+ List storageNodes = new List();
+ foreach (string IPStr in trackerResponse.IPStrs)
+ {
+ StorageNode storage = new StorageNode();
+ storage.GroupName = trackerResponse.GroupName;
+ storage.EndPoint = new IPEndPoint(IPAddress.Parse(IPStr), trackerResponse.Port);
+ storage.StorePathIndex = 0;
+ storageNodes.Add(storage);
+ }
+ return storageNodes.ToArray();
+ }
+ ///
+ /// 上传文件
+ ///
+ /// GetStorageNode方法返回的存储节点
+ /// 文件内容
+ /// 文件扩展名(注意:不包含".")
+ /// 文件名
+ public static string UploadFile(StorageNode storageNode,byte[] contentByte,string fileExt)
+ {
+ FDFSRequest storageRequest = UPLOAD_FILE.Instance.GetRequest(storageNode.EndPoint, storageNode.StorePathIndex, (long)contentByte.Length, fileExt, contentByte);
+ UPLOAD_FILE.Response storageResponse = new UPLOAD_FILE.Response();
+ storageRequest.GetResponse(storageResponse);
+ return storageResponse.FileName;
+ }
+
+ public static string UploadFileByName(StorageNode storageNode, string filename)
+ {
+ using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
+ {
+ string extension = Path.GetExtension(filename).Substring(1);
+ FDFSRequest storageRequest = UPLOAD_FILE.Instance.GetRequest(storageNode.EndPoint, storageNode.StorePathIndex, fs.Length, extension, fs);
+ UPLOAD_FILE.Response storageResponse = new UPLOAD_FILE.Response();
+ storageRequest.GetResponse(storageResponse);
+ return storageResponse.FileName;
+ }
+ }
+
+ ///
+ /// 上传从文件
+ ///
+ /// GetStorageNode方法返回的存储节点
+ /// 文件内容
+ /// 主文件名
+ /// 从文件后缀
+ /// 文件扩展名(注意:不包含".")
+ /// 文件名
+ public static string UploadSlaveFile(string groupName, byte[] contentByte, string master_filename, string prefix_name, string fileExt)
+ {
+ FDFSRequest trackerRequest = QUERY_UPDATE.Instance.GetRequest(groupName, master_filename);
+ QUERY_UPDATE.Response trackerResponse = new QUERY_UPDATE.Response();
+ trackerRequest.GetResponse(trackerResponse);
+ IPEndPoint storeEndPoint = new IPEndPoint(IPAddress.Parse(trackerResponse.IPStr), trackerResponse.Port);
+
+ FDFSRequest storageRequest = UPLOAD_SLAVE_FILE.Instance.GetRequest(storeEndPoint, contentByte.Length, master_filename, prefix_name, fileExt, contentByte);
+ UPLOAD_FILE.Response storageResponse = new UPLOAD_FILE.Response();
+ storageRequest.GetResponse(storageResponse);
+ return storageResponse.FileName;
+ }
+
+
+ ///
+ /// 上传可以Append的文件
+ ///
+ /// GetStorageNode方法返回的存储节点
+ /// 文件内容
+ /// 文件扩展名(注意:不包含".")
+ /// 文件名
+ public static string UploadAppenderFile(StorageNode storageNode, byte[] contentByte, string fileExt)
+ {
+ FDFSRequest storageRequest = UPLOAD_APPEND_FILE.Instance.GetRequest(storageNode.EndPoint, storageNode.StorePathIndex, contentByte.Length, fileExt, contentByte);
+ UPLOAD_APPEND_FILE.Response storageResponse = new UPLOAD_APPEND_FILE.Response();
+ storageRequest.GetResponse(storageResponse);
+ return storageResponse.FileName;
+ }
+ ///
+ /// 附加文件
+ ///
+ /// 组名
+ /// 文件名
+ /// 文件内容
+ public static void AppendFile(string groupName,string fileName, byte[] contentByte)
+ {
+ FDFSRequest trackerRequest = QUERY_UPDATE.Instance.GetRequest(groupName, fileName);
+ QUERY_UPDATE.Response trackerResponse = new QUERY_UPDATE.Response();
+ trackerRequest.GetResponse(trackerResponse);
+ IPEndPoint storeEndPoint = new IPEndPoint(IPAddress.Parse(trackerResponse.IPStr), trackerResponse.Port);
+
+ FDFSRequest storageRequest = APPEND_FILE.Instance.GetRequest(storeEndPoint, fileName, contentByte);
+ storageRequest.GetResponse();
+ }
+ ///
+ /// 删除文件
+ ///
+ /// 组名
+ /// 文件名
+ public static void RemoveFile(string groupName,string fileName)
+ {
+ FDFSRequest trackerRequest = QUERY_UPDATE.Instance.GetRequest(groupName, fileName);
+ QUERY_UPDATE.Response trackerResponse = new QUERY_UPDATE.Response();
+ trackerRequest.GetResponse(trackerResponse);
+ IPEndPoint storeEndPoint = new IPEndPoint(IPAddress.Parse(trackerResponse.IPStr), trackerResponse.Port);
+ FDFSRequest storageRequest = DELETE_FILE.Instance.GetRequest(storeEndPoint, groupName, fileName);
+ storageRequest.GetResponse();
+ }
+ ///
+ /// 下载文件
+ ///
+ /// GetStorageNode方法返回的存储节点
+ /// 文件名
+ /// 文件内容
+ public static byte[] DownloadFile(StorageNode storageNode,string fileName)
+ {
+ FDFSRequest storageRequest = DOWNLOAD_FILE.Instance.GetRequest(storageNode.EndPoint, 0L, 0L, storageNode.GroupName, fileName);
+ DOWNLOAD_FILE.Response storageResponse = new DOWNLOAD_FILE.Response();
+ storageRequest.GetResponse(storageResponse);
+ return storageResponse.Content;
+ }
+ ///
+ /// 增量下载文件
+ ///
+ /// GetStorageNode方法返回的存储节点
+ /// 文件名
+ /// 从文件起始点的偏移量
+ /// 要读取的字节数
+ /// 文件内容
+ public static byte[] DownloadFile(StorageNode storageNode, string fileName, long offset, long length)
+ {
+ FDFSRequest storageRequest = DOWNLOAD_FILE.Instance.GetRequest(storageNode.EndPoint, offset, length, storageNode.GroupName, fileName);
+ DOWNLOAD_FILE.Response storageResponse = new DOWNLOAD_FILE.Response();
+ storageRequest.GetResponse(storageResponse);
+ return storageResponse.Content;
+ }
+
+ public static string DownloadFileEx(StorageNode storageNode, string filename, string destDir, string destFileName = null)
+ {
+ string fullPath = null;
+ if (destFileName == null)
+ {
+ IDictionary metaData = GetMetaData(storageNode, filename);
+ destFileName = metaData["Name"] + Path.GetExtension(filename);
+ }
+ fullPath = Path.Combine(destDir, destFileName);
+ FDFSRequest storageRequest = DOWNLOAD_FILE.Instance.GetRequest(storageNode.EndPoint, 0L, 0L, storageNode.GroupName, filename);
+ DOWNLOAD_FILE.ResponseEx storageResponse = new DOWNLOAD_FILE.ResponseEx(fullPath);
+ storageRequest.GetResponse(storageResponse);
+ return storageResponse.FullPath;
+ }
+
+ ///
+ /// 获取文件信息
+ ///
+ /// GetStorageNode方法返回的存储节点
+ /// 文件名
+ ///
+ public static FDFSFileInfo GetFileInfo(StorageNode storageNode, string fileName)
+ {
+ FDFSRequest storageRequest = QUERY_FILE_INFO.Instance.GetRequest(storageNode.EndPoint, storageNode.GroupName, fileName);
+ FDFSFileInfo result = new FDFSFileInfo();
+ storageRequest.GetResponse(result);
+ return result;
+ }
+
+
+ public static void SetMetaData(StorageNode storageNode, string fileName, IDictionary metadata, MetaDataOption option = MetaDataOption.Overwrite)
+ {
+ FDFSRequest storageRequest = SET_METADATA.Instance.GetRequest(storageNode.EndPoint, storageNode.GroupName, fileName, metadata, option);
+ storageRequest.GetResponse(); // no response body
+ }
+
+ public static IDictionary GetMetaData(StorageNode storageNode, string fileName)
+ {
+ FDFSRequest storageRequest = GET_METADATA.Instance.GetRequest(storageNode.EndPoint, storageNode.GroupName, fileName);
+ GET_METADATA.Response storageResponse = new GET_METADATA.Response();
+ storageRequest.GetResponse(storageResponse);
+ return storageResponse.MetaData;
+ }
+
+
+ }
+}
diff --git a/FastDFSTest/Program.cs b/FastDFSTest/Program.cs
index 0469933..d8e191a 100644
--- a/FastDFSTest/Program.cs
+++ b/FastDFSTest/Program.cs
@@ -1,146 +1,146 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Net;
-using System.IO;
-using System.Threading;
-using System.Drawing;
-
-using FastDFS.Client;
-namespace FastDFS
-{
- class Program
- {
- static void Main(string[] args)
- {
-
- //===========================Initial========================================
- List trackerIPs = new List();
- IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("192.168.81.233"), 22122);
- trackerIPs.Add(endPoint);
- ConnectionManager.Initialize(trackerIPs);
- StorageNode node = FastDFSClient.GetStorageNode("group1");
- //===========================UploadFile=====================================
- byte[] content = null;
- if (File.Exists(@"D:\材料科学与工程基础.doc"))
- {
- FileStream streamUpload = new FileStream(@"D:\材料科学与工程基础.doc", FileMode.Open);
- using (BinaryReader reader = new BinaryReader(streamUpload))
- {
- content = reader.ReadBytes((int)streamUpload.Length);
- }
- }
- //string fileName = FastDFSClient.UploadAppenderFile(node, content, "mdb");
- //主文件
- string fileName = FastDFSClient.UploadFile(node, content, "doc");
-
- //UploadFileByName
- //string fileName = FastDFSClient.UploadFileByName(node, @"D:\材料科学与工程基础.doc");
-
- //从文件
- string slavefileName = FastDFSClient.UploadSlaveFile("group1", content, fileName, "-part1", "doc");
-
- //===========================BatchUploadFile=====================================
- string[] _FileEntries = Directory.GetFiles(@"E:\fastimage\三维", "*.jpg");
- DateTime start = DateTime.Now;
- foreach (string file in _FileEntries)
- {
- string name = Path.GetFileName(file);
- content = null;
- FileStream streamUpload = new FileStream(file, FileMode.Open);
- using (BinaryReader reader = new BinaryReader(streamUpload))
- {
- content = reader.ReadBytes((int)streamUpload.Length);
- }
- //string fileName = FastDFSClient.UploadAppenderFile(node, content, "mdb");
- fileName = FastDFSClient.UploadFile(node, content, "jpg");
- }
- DateTime end = DateTime.Now;
- TimeSpan consume = ((TimeSpan)(end - start));
- double consumeSeconds = Math.Ceiling(consume.TotalSeconds);
- //===========================QueryFile=======================================
- fileName = "M00/03/80/wKhR6VAhwA72jCDyAABYAMjfFsM288.doc";
- FDFSFileInfo fileInfo = FastDFSClient.GetFileInfo(node, fileName);
- Console.WriteLine(string.Format("FileName:{0}", fileName));
- Console.WriteLine(string.Format("FileSize:{0}", fileInfo.FileSize));
- Console.WriteLine(string.Format("CreateTime:{0}", fileInfo.CreateTime));
- Console.WriteLine(string.Format("Crc32:{0}", fileInfo.Crc32));
- //==========================AppendFile=======================================
- FastDFSClient.AppendFile("group1", fileName, content);
- FastDFSClient.AppendFile("group1", fileName, content);
-
- //===========================DownloadFile====================================
- fileName = "M00/00/00/wKhR6VAAAN7J2FLQAABYAMjfFsM849.doc";
- string localName = @"D:\SZdownload.doc";
- if (File.Exists(@"D:\SZdownload.doc"))
- File.Delete(@"D:\SZdownload.doc");
- if (fileInfo.FileSize >= 1024)//如果文件大小大于1KB 分次写入
- {
- FileStream fs = new FileStream(localName, FileMode.OpenOrCreate, FileAccess.Write);
- //string name_ = LocalName.Substring(LocalName.LastIndexOf("\\") + 1, LocalName.Length - LocalName.LastIndexOf("\\") - 1);
- long offset = 0;
- long len = 1024;
- while (len > 0)
- {
- byte[] buffer = new byte[len];
- buffer = FastDFSClient.DownloadFile(node, fileName, offset, len);
- fs.Write(buffer, 0, int.Parse(len.ToString()));
- fs.Flush();
- // setrichtext(name_ + "已经下载:" + (offset / fileInfo.FileSize) + "%");
- offset = offset + len;
- len = (fileInfo.FileSize - offset) >= 1024 ? 1024 : (fileInfo.FileSize - offset);
- }
- fs.Close();
-
- }
- else//如果文件大小小小于1KB 直接写入文件
- {
- byte[] buffer = new byte[fileInfo.FileSize];
- buffer = FastDFSClient.DownloadFile(node, fileName);
- FileStream fs = new FileStream(localName, FileMode.OpenOrCreate, FileAccess.Write);
- fs.Write(buffer, 0, buffer.Length);
- fs.Flush();
- fs.Close();
- }
- //byte[] buffer = FastDFSClient.DownloadFile(node, fileName, 0L, 0L);
- //if (File.Exists(@"D:\SZdownload.mdb"))
- // File.Delete(@"D:\SZdownload.mdb");
- //FileStream stream = new FileStream(@"D:\SZdownload.mdb", FileMode.CreateNew);
- //using (BinaryWriter write = new BinaryWriter(stream, Encoding.BigEndianUnicode))
- //{
- // write.Write(buffer);
- // write.Close();
- //}
- //stream.Close();
- //===========================RemoveFile=======================================
- //FastDFSClient.RemoveFile("group1", fileName);
-
- //===========================Http测试,流读取=======================================
- string url = "http://img13.360buyimg.com/da/g5/M02/0D/16/rBEDik_nOJ0IAAAAAAA_cbJCY-UAACrRgMhVLEAAD-J352.jpg";
- System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
- System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
- Image myImage = Image.FromStream(res.GetResponseStream());
- myImage.Save("c:\\fast.jpg");//保存
- //===========================Http测试,直接下载=======================================
- using (WebClient web = new WebClient())
- {
- web.DownloadFile("http://img13.360buyimg.com/da/g5/M02/0D/16/rBEDik_nOJ0IAAAAAAA_cbJCY-UAACrRgMhVLEAAD-J352.jpg", "C:\\abc.jpg");
- web.DownloadFile("http://192.168.81.233/M00/00/00/wKhR6VADbNr5s7ODAAIOGO1_YmA574.jpg", "C:\\abc.jpg");
- }
- //===========================防盗链请求=======================================
- start = new DateTime(1970, 1, 1);
- end = DateTime.Now;
- consume = (TimeSpan)(end - start);
- int ts = (int)(consume.TotalSeconds);
- string pwd = FastDFS.Client.Util.GetToken("M00/03/81/wKhR6VAh0sfyH0AxAABYAMjfFsM301-part1.doc", ts, "FastDFS1qaz2wsxsipsd");
- string anti_steel_url = "http://192.168.81.233/M00/03/81/wKhR6VAh0sfyH0AxAABYAMjfFsM301-part1.doc?token=" + pwd + "&ts=" + ts;
- string url1 = "http://192.168.81.233/M00/01/E0/wKhR6VANJBiInHb5AAClVeZnxGg341.pdf";
- using (WebClient web = new WebClient())
- {
- web.DownloadFile(anti_steel_url, "C:\\salve.doc");
- }
- Console.WriteLine("Complete");
- Console.Read();
- }
- }
-}
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Net;
+using System.IO;
+using System.Threading;
+using System.Drawing;
+
+using FastDFS.Client;
+namespace FastDFS
+{
+ class Program
+ {
+ static void Main(string[] args)
+ {
+
+ //===========================Initial========================================
+ List trackerIPs = new List();
+ IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("192.168.81.233"), 22122);
+ trackerIPs.Add(endPoint);
+ ConnectionManager.Initialize(trackerIPs);
+ StorageNode node = FastDFSClient.GetStorageNode("group1");
+ //===========================UploadFile=====================================
+ byte[] content = null;
+ if (File.Exists(@"D:\材料科学与工程基础.doc"))
+ {
+ FileStream streamUpload = new FileStream(@"D:\材料科学与工程基础.doc", FileMode.Open);
+ using (BinaryReader reader = new BinaryReader(streamUpload))
+ {
+ content = reader.ReadBytes((int)streamUpload.Length);
+ }
+ }
+ //string fileName = FastDFSClient.UploadAppenderFile(node, content, "mdb");
+ //主文件
+ string fileName = FastDFSClient.UploadFile(node, content, "doc");
+
+ //UploadFileByName
+ //string fileName = FastDFSClient.UploadFileByName(node, @"D:\材料科学与工程基础.doc");
+
+ //从文件
+ string slavefileName = FastDFSClient.UploadSlaveFile("group1", content, fileName, "-part1", "doc");
+
+ //===========================BatchUploadFile=====================================
+ string[] _FileEntries = Directory.GetFiles(@"E:\fastimage\三维", "*.jpg");
+ DateTime start = DateTime.Now;
+ foreach (string file in _FileEntries)
+ {
+ string name = Path.GetFileName(file);
+ content = null;
+ FileStream streamUpload = new FileStream(file, FileMode.Open);
+ using (BinaryReader reader = new BinaryReader(streamUpload))
+ {
+ content = reader.ReadBytes((int)streamUpload.Length);
+ }
+ //string fileName = FastDFSClient.UploadAppenderFile(node, content, "mdb");
+ fileName = FastDFSClient.UploadFile(node, content, "jpg");
+ }
+ DateTime end = DateTime.Now;
+ TimeSpan consume = ((TimeSpan)(end - start));
+ double consumeSeconds = Math.Ceiling(consume.TotalSeconds);
+ //===========================QueryFile=======================================
+ fileName = "M00/03/80/wKhR6VAhwA72jCDyAABYAMjfFsM288.doc";
+ FDFSFileInfo fileInfo = FastDFSClient.GetFileInfo(node, fileName);
+ Console.WriteLine(string.Format("FileName:{0}", fileName));
+ Console.WriteLine(string.Format("FileSize:{0}", fileInfo.FileSize));
+ Console.WriteLine(string.Format("CreateTime:{0}", fileInfo.CreateTime));
+ Console.WriteLine(string.Format("Crc32:{0}", fileInfo.Crc32));
+ //==========================AppendFile=======================================
+ FastDFSClient.AppendFile("group1", fileName, content);
+ FastDFSClient.AppendFile("group1", fileName, content);
+
+ //===========================DownloadFile====================================
+ fileName = "M00/00/00/wKhR6VAAAN7J2FLQAABYAMjfFsM849.doc";
+ string localName = @"D:\SZdownload.doc";
+ if (File.Exists(@"D:\SZdownload.doc"))
+ File.Delete(@"D:\SZdownload.doc");
+ if (fileInfo.FileSize >= 1024)//如果文件大小大于1KB 分次写入
+ {
+ FileStream fs = new FileStream(localName, FileMode.OpenOrCreate, FileAccess.Write);
+ //string name_ = LocalName.Substring(LocalName.LastIndexOf("\\") + 1, LocalName.Length - LocalName.LastIndexOf("\\") - 1);
+ long offset = 0;
+ long len = 1024;
+ while (len > 0)
+ {
+ byte[] buffer = new byte[len];
+ buffer = FastDFSClient.DownloadFile(node, fileName, offset, len);
+ fs.Write(buffer, 0, int.Parse(len.ToString()));
+ fs.Flush();
+ // setrichtext(name_ + "已经下载:" + (offset / fileInfo.FileSize) + "%");
+ offset = offset + len;
+ len = (fileInfo.FileSize - offset) >= 1024 ? 1024 : (fileInfo.FileSize - offset);
+ }
+ fs.Close();
+
+ }
+ else//如果文件大小小小于1KB 直接写入文件
+ {
+ byte[] buffer = new byte[fileInfo.FileSize];
+ buffer = FastDFSClient.DownloadFile(node, fileName);
+ FileStream fs = new FileStream(localName, FileMode.OpenOrCreate, FileAccess.Write);
+ fs.Write(buffer, 0, buffer.Length);
+ fs.Flush();
+ fs.Close();
+ }
+ //byte[] buffer = FastDFSClient.DownloadFile(node, fileName, 0L, 0L);
+ //if (File.Exists(@"D:\SZdownload.mdb"))
+ // File.Delete(@"D:\SZdownload.mdb");
+ //FileStream stream = new FileStream(@"D:\SZdownload.mdb", FileMode.CreateNew);
+ //using (BinaryWriter write = new BinaryWriter(stream, Encoding.BigEndianUnicode))
+ //{
+ // write.Write(buffer);
+ // write.Close();
+ //}
+ //stream.Close();
+ //===========================RemoveFile=======================================
+ //FastDFSClient.RemoveFile("group1", fileName);
+
+ //===========================Http测试,流读取=======================================
+ string url = "http://img13.360buyimg.com/da/g5/M02/0D/16/rBEDik_nOJ0IAAAAAAA_cbJCY-UAACrRgMhVLEAAD-J352.jpg";
+ System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
+ System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
+ Image myImage = Image.FromStream(res.GetResponseStream());
+ myImage.Save("c:\\fast.jpg");//保存
+ //===========================Http测试,直接下载=======================================
+ using (WebClient web = new WebClient())
+ {
+ web.DownloadFile("http://img13.360buyimg.com/da/g5/M02/0D/16/rBEDik_nOJ0IAAAAAAA_cbJCY-UAACrRgMhVLEAAD-J352.jpg", "C:\\abc.jpg");
+ web.DownloadFile("http://192.168.81.233/M00/00/00/wKhR6VADbNr5s7ODAAIOGO1_YmA574.jpg", "C:\\abc.jpg");
+ }
+ //===========================防盗链请求=======================================
+ start = new DateTime(1970, 1, 1);
+ end = DateTime.Now;
+ consume = (TimeSpan)(end - start);
+ int ts = (int)(consume.TotalSeconds);
+ string pwd = FastDFS.Client.Util.GetToken("M00/03/81/wKhR6VAh0sfyH0AxAABYAMjfFsM301-part1.doc", ts, "FastDFS1qaz2wsxsipsd");
+ string anti_steel_url = "http://192.168.81.233/M00/03/81/wKhR6VAh0sfyH0AxAABYAMjfFsM301-part1.doc?token=" + pwd + "&ts=" + ts;
+ string url1 = "http://192.168.81.233/M00/01/E0/wKhR6VANJBiInHb5AAClVeZnxGg341.pdf";
+ using (WebClient web = new WebClient())
+ {
+ web.DownloadFile(anti_steel_url, "C:\\salve.doc");
+ }
+ Console.WriteLine("Complete");
+ Console.Read();
+ }
+ }
+}
diff --git a/FastDFSTest/Properties/AssemblyInfo.cs b/FastDFSTest/Properties/AssemblyInfo.cs
index 486b622..0a94979 100644
--- a/FastDFSTest/Properties/AssemblyInfo.cs
+++ b/FastDFSTest/Properties/AssemblyInfo.cs
@@ -1,36 +1,36 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// 有关程序集的常规信息通过以下
-// 特性集控制。更改这些特性值可修改
-// 与程序集关联的信息。
-[assembly: AssemblyTitle("FastDFSTest")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("FastDFSTest")]
-[assembly: AssemblyCopyright("Copyright © 2012")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// 将 ComVisible 设置为 false 使此程序集中的类型
-// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
-// 则将该类型上的 ComVisible 特性设置为 true。
-[assembly: ComVisible(false)]
-
-// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
-[assembly: Guid("714b3a01-f73b-4a00-9b8a-d55de1810413")]
-
-// 程序集的版本信息由下面四个值组成:
-//
-// 主版本
-// 次版本
-// 内部版本号
-// 修订号
-//
-// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
-// 方法是按如下所示使用“*”:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的常规信息通过以下
+// 特性集控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("FastDFSTest")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("FastDFSTest")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 使此程序集中的类型
+// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
+// 则将该类型上的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("714b3a01-f73b-4a00-9b8a-d55de1810413")]
+
+// 程序集的版本信息由下面四个值组成:
+//
+// 主版本
+// 次版本
+// 内部版本号
+// 修订号
+//
+// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
+// 方法是按如下所示使用“*”:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]