-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormUploadFile.cs
More file actions
101 lines (87 loc) · 3.05 KB
/
FormUploadFile.cs
File metadata and controls
101 lines (87 loc) · 3.05 KB
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
using System.Windows.Forms;
namespace C_Sharp_SFTP_Client
{
public partial class FormUploadFile : Form
{
public FormUploadFile()
{
InitializeComponent();
}
private void btnUploadFiles_Click(object sender, EventArgs e)
{
if (Utilities.CheckIfInputsOK(txtSource.Text))
{
UserInfo._remoteDirectory = txtDestination.Text;
//get the selected file
string selectedFilePath = GetSelectedFile();
if(!string.IsNullOrEmpty(selectedFilePath))
{
//upload the file
Utilities.HandleFileUpload(selectedFilePath);
RefreshView_FilesOnLocal();
RefreshView_FilesOnServer();
return;
}
}
MessageBox.Show("Please check that you have selected an item to upload, and that all necessary inputs are populated!");
}
private string GetSelectedFile()
{
try
{
//get selected Item
ListViewItem selectedItem = Utilities.GetSelectedListViewItem(ref listViewSource);
if (selectedItem != null)
{
//get name of selected Item
string itemName = selectedItem.Text;
//return the path of the selected file:
return Path.Combine(txtSource.Text, itemName);
}
}
catch (Exception)
{
MessageBox.Show("Please select a file to upload to the remote server!");
throw;
}
return string.Empty;
}
private void btnRefresh_Click(object sender, EventArgs e)
{
RefreshView_FilesOnServer();
}
private void RefreshView_FilesOnServer()
{
if (Utilities.CheckIfInputsOK(txtDestination.Text))
{
UserInfo._remoteDirectory = txtDestination.Text;
}
else
{
UserInfo._remoteDirectory = "";
}
Utilities.HandleReadFilenamesFromServer(ref listViewDestination);
listViewSource.Update();
}
private void btnRefreshLocal_Click(object sender, EventArgs e)
{
//UserInfo._localDirectory = txtSource.Text;
RefreshView_FilesOnLocal();
}
private void RefreshView_FilesOnLocal()
{
if (Utilities.CheckIfInputsOK(txtSource.Text))
{
Utilities.ClearListViewItems(ref listViewSource);
listViewSource = Utilities.GetLocalDirListViewItems(txtSource.Text, ref listViewSource);
listViewSource.Update();
//get all the listed files on our side
}
}
private void formClosingEvent(object sender, FormClosedEventArgs e)
{
UserInfo._homeForm.Show();
this.Hide();
}
}
}