/
SendZipFile.cs
77 lines (64 loc) · 2.65 KB
/
SendZipFile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace DistributeLib
{
public class SendZipFile : EventArgs
{
private ZipFileCreated mZipFileCreated;
private GitUtilCommnad mGitutilCommand;
delegate void OnZipFileFTPFinished();
public SendZipFile(ZipFileCreated zipFile, GitUtilCommnad gitUtilCommand)
{
this.mGitutilCommand = gitUtilCommand;
this.mZipFileCreated = zipFile;
SendAsync();
}
private void SendAsync()
{
using (WebClient myWebClient = new WebClient())
{
try
{
myWebClient.Credentials = new NetworkCredential(mGitutilCommand.ExternalFTPUser.Normalize(),
mGitutilCommand.ExternalFTPPassword.Normalize());
myWebClient.UploadFileCompleted += OnFileUploadCompleted;
myWebClient.UploadProgressChanged += OnProgressUpload;
myWebClient.UploadFileAsync(new Uri(string.Format(@"ftp://{0}/{1}",
mGitutilCommand.ExternalFTPPath,
new FileInfo(mGitutilCommand.CreatedZipFile).Name)), "STOR", mZipFileCreated.filePath, Guid.NewGuid().ToString());
Uri tmp = new Uri(string.Format(@"ftp://{0}/{1}",
mGitutilCommand.ExternalFTPPath, new FileInfo(mGitutilCommand.CreatedZipFile).Name));
}
catch (Exception e)
{
string error = e.Message;
}
}
}
private void OnProgressUpload(object sender, UploadProgressChangedEventArgs e)
{
Console.WriteLine("Sent {0} bytes of total {1}, percent = {2}", e.BytesSent, e.TotalBytesToSend, e.ProgressPercentage);
}
private void OnFileUploadCompleted(object sender, UploadFileCompletedEventArgs e)
{
if (e.Error != null)
{
Console.WriteLine("There is a problem with the FTP transfer!");
Console.WriteLine("If you are using a FTP sevrer behind a NAT, make sure to allow port redirect in firewall");
Console.WriteLine();
Console.WriteLine("Press return to exit.");
}
else
{
Console.WriteLine("File upload completed!");
Console.WriteLine();
Console.WriteLine("Press return to exit.");
}
}
}
}