-
-
Notifications
You must be signed in to change notification settings - Fork 659
/
ConnectProxySocks5.cs
106 lines (77 loc) · 2.69 KB
/
ConnectProxySocks5.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using FluentFTP;
using FluentFTP.Proxy;
using FluentFTP.Proxy.AsyncProxy;
using FluentFTP.Proxy.SyncProxy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Examples {
internal static class ConnectProxySocks5 {
// Add your Proxy server details here
static string proxy_host = "http://myproxy.com/";
static int proxy_port = 1234;
static string proxy_user = "system";
static string proxy_pass = "123";
// Add your FTP server details here
static string ftp_host = "123.123.123.123";
static int ftp_port = 1234;
static string ftp_user = "david";
static string ftp_pass = "pass123";
public static void ConnectAndGetListing() {
// create an FTP client connecting through a SOCKS5 Proxy
var client = new FtpClientSocks5Proxy(new FtpProxyProfile() {
ProxyHost = proxy_host,
ProxyPort = proxy_port,
ProxyCredentials = new NetworkCredential(proxy_user, proxy_pass),
FtpHost = ftp_host,
FtpPort = ftp_port,
FtpCredentials = new NetworkCredential(ftp_user, ftp_pass),
});
// begin connecting to the server
client.Connect();
// get a list of files and directories in the "/" folder
foreach (FtpListItem item in client.GetListing("/")) {
// if this is a file
if (item.Type == FtpObjectType.File) {
// get the file size
long size = client.GetFileSize(item.FullName);
// get modified date/time
DateTime time = client.GetModifiedTime(item.FullName);
// print out the file name
Console.WriteLine(item.FullName + " - " + size.FormatBytes() + " - " + time.ToShortDateString());
}
// if this is a folder
else if (item.Type == FtpObjectType.Directory) {
// print out the folder name
Console.WriteLine(item.FullName);
}
}
}
public static void ConnectAndManipulate() {
// create an FTP client connecting through a SOCKS5 Proxy
var client = new FtpClientSocks5Proxy(new FtpProxyProfile() {
ProxyHost = proxy_host,
ProxyPort = proxy_port,
ProxyCredentials = new NetworkCredential(proxy_user, proxy_pass),
FtpHost = ftp_host,
FtpPort = ftp_port,
FtpCredentials = new NetworkCredential(ftp_user, ftp_pass),
});
// begin connecting to the server
client.Connect();
// upload a file
client.UploadFile(@"C:\MyVideo.mp4", "/htdocs/MyVideo.mp4");
// rename the uploaded file
client.Rename("/htdocs/MyVideo.mp4", "/htdocs/MyVideo_2.mp4");
// download the file again
client.DownloadFile(@"C:\MyVideo_2.mp4", "/htdocs/MyVideo_2.mp4");
// delete the file
client.DeleteFile("/htdocs/MyVideo_2.mp4");
// disconnect! good bye!
client.Disconnect();
}
}
}