I am making a simple ftp app, when I click the browse button, the full path of the files will be added in the first ListBox. When I click on the Send Files button, it will execute and the full path will appear in the second ListBox. What I want to achieve is that, when a particular path is in the second ListBox, it will be removed in the first ListBox.
Here' what I have so far.
private void button2_Click(object sender, EventArgs e)
{
List<string> str = new List<string>();
OpenFileDialog v1 = new OpenFileDialog();
v1.Multiselect = true;
if (v1.ShowDialog() == DialogResult.Cancel)
return;
foreach (string s in v1.FileNames)
{
////listBox1.Items.Add(Path.GetFileName(s));
listTransfer.Items.Add(Path.GetFullPath(s));
str.Add(s);
}
}
private void button1_Click(object sender, EventArgs e)
{
SendFiles();
}
private int SendFiles()
{
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Ftp,
HostName = "192.168.1.3",
UserName = "Admin",
Password = "foxtrotAlpha",
PortNumber = 21
// SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx...="
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
// transferResult = session.PutFiles(@"d:\upload\*", "/transfer/", false, transferOptions);
foreach (var listBoxItem in listTransfer.Items)
{
string item = listBoxItem.ToString();
string[] result = item.Split(',');
transferResult = session.PutFiles(@result[0], "/_transfer/", false, transferOptions);
// Throw on any error
transferResult.Check();
// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
lblCompleted.Text = transfer.FileName.ToString();
listCompleted.Items.Add(lblCompleted.Text);
}
}
}
return 0;
}
catch (Exception e )
{
MessageBox.Show(e.Message.ToString(),"FTP",MessageBoxButtons.OK,MessageBoxIcon.Error);
return 1;
}
}
Consider putting
somewhere suitable, like above
//print results
..