|
|
@@ -27,10 +27,18 @@ namespace CallCenter.Utility
|
|
27
|
27
|
return res;
|
|
28
|
28
|
}
|
|
29
|
29
|
FileInfo fileInf = new FileInfo(localFile);
|
|
|
30
|
+ //改后文件
|
|
|
31
|
+ #region 改后文件
|
|
|
32
|
+ string temp_filename = localFile.Split('\\').Last().Split('.')[0] + "_temp";
|
|
|
33
|
+ string localfileAft = Path.GetDirectoryName(localFile) + "\\" + temp_filename + ".wav";
|
|
|
34
|
+ FileInfo fileInfAft = new FileInfo(localfileAft);
|
|
|
35
|
+ #endregion
|
|
30
|
36
|
string ftpURI = "ftp://" + ftpPath + "/";
|
|
31
|
37
|
string uri = ftpURI + fileInf.Name;
|
|
|
38
|
+ string uriAft = ftpURI + fileInfAft.Name;
|
|
32
|
39
|
FtpWebRequest reqFTP;
|
|
33
|
|
-
|
|
|
40
|
+ //20180209
|
|
|
41
|
+ //System.GC.Collect();
|
|
34
|
42
|
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));// 根据uri创建FtpWebRequest对象
|
|
35
|
43
|
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);// ftp用户名和密码
|
|
36
|
44
|
reqFTP.KeepAlive = false;// 默认为true,连接不会被关闭 // 在一个命令之后被执行
|
|
|
@@ -44,32 +52,83 @@ namespace CallCenter.Utility
|
|
44
|
52
|
|
|
45
|
53
|
// 打开一个文件流 (System.IO.FileStream) 去读上传的文件
|
|
46
|
54
|
//FileStream fs = fileInf.OpenRead();
|
|
47
|
|
- FileStream fs = new FileStream(localFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
|
48
|
|
- try
|
|
|
55
|
+ using (FileStream fs = new FileStream(localFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
|
49
|
56
|
{
|
|
50
|
|
- res += uri+localFile;
|
|
51
|
|
- //Stream strm = reqFTP.GetRequestStream();// 把上传的文件写入流
|
|
52
|
|
- StreamReader strm = new StreamReader(fs, System.Text.Encoding.Default);
|
|
53
|
|
- contentLen = fs.Read(buff, 0, buffLength);// 每次读文件流的2kb
|
|
54
|
|
- //while (contentLen != 0)// 流内容没有结束
|
|
55
|
|
- //{
|
|
56
|
|
- // // 把内容从file stream 写入 upload stream
|
|
57
|
|
- // strm.Write(buff, 0, contentLen);
|
|
58
|
|
- // contentLen = fs.Read(buff, 0, buffLength);
|
|
59
|
|
- //}
|
|
60
|
|
- StringBuilder sb = new StringBuilder();
|
|
61
|
|
- while (!strm.EndOfStream)
|
|
|
57
|
+ try
|
|
|
58
|
+ {
|
|
|
59
|
+ res += uri + localFile;
|
|
|
60
|
+ using (Stream strm = reqFTP.GetRequestStream())// 把上传的文件写入流
|
|
|
61
|
+ {
|
|
|
62
|
+ //StreamReader strm = new StreamReader(fs, System.Text.Encoding.Default);
|
|
|
63
|
+ contentLen = fs.Read(buff, 0, buffLength);// 每次读文件流的2kb
|
|
|
64
|
+ while (contentLen != 0)// 流内容没有结束
|
|
|
65
|
+ {
|
|
|
66
|
+ // 把内容从file stream 写入 upload stream
|
|
|
67
|
+ strm.Write(buff, 0, contentLen);
|
|
|
68
|
+ contentLen = fs.Read(buff, 0, buffLength);
|
|
|
69
|
+ }
|
|
|
70
|
+ //StringBuilder sb = new StringBuilder();
|
|
|
71
|
+ //while (!strm.EndOfStream)
|
|
|
72
|
+ //{
|
|
|
73
|
+ // sb.AppendLine(strm.ReadLine() + "<br>");
|
|
|
74
|
+ //}
|
|
|
75
|
+ }
|
|
|
76
|
+ // 关闭两个流
|
|
|
77
|
+ //strm.Close();
|
|
|
78
|
+ fs.Close();
|
|
|
79
|
+ res = "上传成功!";
|
|
|
80
|
+ }
|
|
|
81
|
+ catch (Exception ex)
|
|
62
|
82
|
{
|
|
63
|
|
- sb.AppendLine(strm.ReadLine() + "<br>");
|
|
|
83
|
+ res += "上传文件【" + ftpPath + "/" + fileInf.Name + "】时,发生错误:" + ex.Message + "<br/>。路径:" + localFile;
|
|
64
|
84
|
}
|
|
65
|
|
- // 关闭两个流
|
|
66
|
|
- strm.Close();
|
|
67
|
|
- fs.Close();
|
|
68
|
|
- res = "上传成功!";
|
|
69
|
85
|
}
|
|
70
|
|
- catch (Exception ex)
|
|
|
86
|
+ FtpWebRequest reqFTP1;
|
|
|
87
|
+ //20180209
|
|
|
88
|
+ //System.GC.Collect();
|
|
|
89
|
+ reqFTP1 = (FtpWebRequest)FtpWebRequest.Create(new Uri(uriAft));// 根据uri创建FtpWebRequest对象
|
|
|
90
|
+ reqFTP1.Credentials = new NetworkCredential(ftpUserID, ftpPassword);// ftp用户名和密码
|
|
|
91
|
+ reqFTP1.KeepAlive = false;// 默认为true,连接不会被关闭 // 在一个命令之后被执行
|
|
|
92
|
+ reqFTP1.Method = WebRequestMethods.Ftp.UploadFile;// 指定执行什么命令
|
|
|
93
|
+ reqFTP1.UseBinary = true;// 指定数据传输类型
|
|
|
94
|
+ reqFTP1.UsePassive = true;
|
|
|
95
|
+ reqFTP1.ContentLength = fileInfAft.Length;// 上传文件时通知服务器文件的大小
|
|
|
96
|
+ int buffLengthaft = 2048;// 缓冲大小设置为2kb
|
|
|
97
|
+ byte[] buffaft = new byte[buffLengthaft];
|
|
|
98
|
+ int contentLenaft;
|
|
|
99
|
+
|
|
|
100
|
+ // 打开一个文件流 (System.IO.FileStream) 去读上传的文件
|
|
|
101
|
+ //FileStream fs = fileInf.OpenRead();
|
|
|
102
|
+ using (FileStream fs1 = new FileStream(localfileAft, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
|
71
|
103
|
{
|
|
72
|
|
- res += "上传文件【" + ftpPath + "/" + fileInf.Name + "】时,发生错误:" + ex.Message + "<br/>。路径:"+localFile;
|
|
|
104
|
+ try
|
|
|
105
|
+ {
|
|
|
106
|
+ res += uriAft + localfileAft;
|
|
|
107
|
+ using (Stream strm1 = reqFTP1.GetRequestStream())// 把上传的文件写入流
|
|
|
108
|
+ {
|
|
|
109
|
+ //StreamReader strm = new StreamReader(fs, System.Text.Encoding.Default);
|
|
|
110
|
+ contentLenaft = fs1.Read(buffaft, 0, buffLengthaft);// 每次读文件流的2kb
|
|
|
111
|
+ while (contentLenaft != 0)// 流内容没有结束
|
|
|
112
|
+ {
|
|
|
113
|
+ // 把内容从file stream 写入 upload stream
|
|
|
114
|
+ strm1.Write(buffaft, 0, contentLenaft);
|
|
|
115
|
+ contentLenaft = fs1.Read(buffaft, 0, buffLengthaft);
|
|
|
116
|
+ }
|
|
|
117
|
+ //StringBuilder sb = new StringBuilder();
|
|
|
118
|
+ //while (!strm.EndOfStream)
|
|
|
119
|
+ //{
|
|
|
120
|
+ // sb.AppendLine(strm.ReadLine() + "<br>");
|
|
|
121
|
+ //}
|
|
|
122
|
+ }
|
|
|
123
|
+ // 关闭两个流
|
|
|
124
|
+ //strm.Close();
|
|
|
125
|
+ fs1.Close();
|
|
|
126
|
+ res = "上传成功!";
|
|
|
127
|
+ }
|
|
|
128
|
+ catch (Exception ex)
|
|
|
129
|
+ {
|
|
|
130
|
+ res += "上传文件【" + ftpPath + "/" + fileInf.Name + "】时,发生错误:" + ex.Message + "<br/>。路径:" + localFile;
|
|
|
131
|
+ }
|
|
73
|
132
|
}
|
|
74
|
133
|
return res;
|
|
75
|
134
|
}
|