forked from ispysoftware/iSpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFTPConfig.cs
144 lines (130 loc) · 4.97 KB
/
FTPConfig.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using System;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Windows.Forms;
using iSpyApplication.Properties;
using iSpyApplication.Utilities;
namespace iSpyApplication.Controls
{
public partial class FTPConfig : Form
{
public configurationServer FTP;
public FTPConfig()
{
InitializeComponent();
RenderResources();
}
private void RenderResources()
{
Text = LocRm.GetString("FTPEditor");
LocRm.SetString(label64,"Name");
LocRm.SetString(label62, "Server");
LocRm.SetString(label66, "Port");
LocRm.SetString(label63, "Username");
LocRm.SetString(label65, "Password");
LocRm.SetString(chkUsePassive, "PassiveMode");
LocRm.SetString(chkFTPRename, "UploadTempFileRename");
LocRm.SetString(btnSaveFTP, "OK");
LocRm.SetString(btnTest, "Test");
}
private void FTPEditor_Load(object sender, EventArgs e)
{
txtServerName.Text = FTP.name;
txtFTPServer.Text = FTP.server;
if (string.IsNullOrEmpty(txtFTPServer.Text))
txtFTPServer.Text = "ftp://";
txtFTPUsername.Text = FTP.username;
txtFTPPassword.Text = FTP.password;
txtFTPPort.Value = FTP.port;
chkFTPRename.Checked = FTP.rename;
chkUsePassive.Checked = FTP.usepassive;
chkSFTP.Checked = FTP.sftp;
if (string.IsNullOrEmpty(FTP.ident))
FTP.ident = Guid.NewGuid().ToString();
}
private void btnSaveFTP_Click(object sender, EventArgs e)
{
FTP.name = txtServerName.Text;
FTP.sftp = chkSFTP.Checked;
CleanData();
FTP.server = txtFTPServer.Text;
FTP.username = txtFTPUsername.Text;
FTP.password = txtFTPPassword.Text;
FTP.port = (int)txtFTPPort.Value;
FTP.rename = chkFTPRename.Checked;
FTP.usepassive = chkUsePassive.Checked;
DialogResult = DialogResult.OK;
Close();
}
string _testloc = "test.jpg";
private void btnTest_Click(object sender, EventArgs e)
{
var p = new Prompt(LocRm.GetString("UploadTo"), _testloc);
p.ShowDialog(this);
if (p.Val != "")
{
_testloc = p.Val;
using (var imageStream = new MemoryStream())
{
try
{
Resources.cam_offline.Save(imageStream, ImageFormat.Jpeg);
string error;
CleanData();
string fn = string.Format(CultureInfo.InvariantCulture, _testloc, Helper.Now);
int port = (int) txtFTPPort.Value;
if ((new AsynchronousFtpUpLoader()).FTP(txtFTPServer.Text, port,
chkUsePassive.Checked,
txtFTPUsername.Text, txtFTPPassword.Text, fn, 0,
"", out error, chkFTPRename.Checked, chkSFTP.Checked, imageStream.ToArray()))
{
MessageBox.Show(LocRm.GetString("ImageUploaded"), LocRm.GetString("Success"));
}
else
MessageBox.Show(string.Format("{0}: {1}", LocRm.GetString("UploadFailed"), error), LocRm.GetString("Failed"));
}
catch (Exception ex)
{
Logger.LogException(ex);
MessageBox.Show(ex.Message);
}
imageStream.Close();
}
}
}
private void CleanData()
{
txtFTPServer.Text = txtFTPServer.Text.Trim('/');
bool sftp = chkSFTP.Checked;
if (!sftp)
{
if (txtFTPServer.Text.IndexOf("://", StringComparison.Ordinal) == -1)
{
txtFTPServer.Text = "ftp://" + txtFTPServer.Text;
}
}
else
{
int i = txtFTPServer.Text.IndexOf("://", StringComparison.Ordinal);
if (i != -1 && i + 3 < txtFTPServer.Text.Length)
{
txtFTPServer.Text = txtFTPServer.Text.Substring(i + 3);
}
}
}
private void chkSFTP_CheckedChanged(object sender, EventArgs e)
{
if (chkSFTP.Checked)
{
if (txtFTPPort.Value == 21)
txtFTPPort.Value = 22;
}
else
{
if (txtFTPPort.Value == 22)
txtFTPPort.Value = 21;
}
}
}
}