Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3.9k views
in Java FTP by (260 points)
Hi, I'm all new to both VB.NET and to the FTP stuff (well in programming anyway)

I've done the basic program with the button and the listbox and that is working just fine :)

But i now want to add 2 extra buttons,
One called rename the other Delete.

What do i add to rename a selected file in that listbox to say "Thisisrenamed.txt"
And when i click the delete button i want it to delete the selected file.

Cheers

Neil

p.s. while i wait for an answer i will be trying several things to get it working but i'm stuck on how to get it to delete the selected file in the listbox.

6 Answers

0 votes
by (51.6k points)
All you need to do is find out what the current selection is and then call the DeleteFile method with this file-name.

- Hans (EnterpriseDT)
0 votes
by (260 points)
All you need to do is find out what the current selection is and then call the DeleteFile method with this file-name.

- Hans (EnterpriseDT)


I now have a strange problem. I've done a simple VB program from your tutorial and when i click the button i get a list of files, but if i click on the button again it seems to loose the directory i was in an list the structure of my hosting:-

Domain
imap
mail
public_html (Where my test folder is)
user_backups.


Why is this?
0 votes
by (51.6k points)
It's a bit hard to say without seeing your code. Could you please post the relevant portions? Please enclose your code snippets in [code]...[/code].

- Hans (EnterpriseDT)
0 votes
by (260 points)
It's a bit hard to say without seeing your code. Could you please post the relevant portions? Please enclose your code snippets in
...
.

- Hans (EnterpriseDT)


I'm using Visual Studio 2005

When you click on the FTPConnection icon at the bottom there is what i've got set:-

LocalDirectory = Null
Password = MyFTPpassword
serveraddress = ftp.hobbit-hosting.com
ServerDirectory = public_html/ftptest
ServerPort = 21
Username = MyFTPusername

Here is the VB Code

Imports System
Imports System.Windows.Forms
Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Try
            ' Clear the list-box
            FilesListBox.Items.Clear()

            ' Connect, get files and close
            FtpConnection1.Connect()
            FilesListBox.Items.AddRange(FtpConnection1.GetFiles())
            FtpConnection1.Close()

        Catch ex As Exception
            If FtpConnection1.IsConnected Then
                FtpConnection1.Close()
            End If
            MessageBox.Show(Me, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub


End Class
0 votes
by (51.6k points)
Yes, there is a problem here. The problem is that the ServerDirectory is cleared when the connection is closed. To be honest I can't see any reason why this was done. It has been fixed and will not happen in the next version. Thank you for pointing this out. Until the next release please work around the problem by setting the directory back to the desired directory before reconnecting.

In other words, please change you code to something like the following:
        Try
            ' Clear the list-box
            FilesListBox.Items.Clear()

            ' Connect, get files and close
            ServerDirectory = "/public_html/ftptest";
            FtpConnection1.Connect()
            FilesListBox.Items.AddRange(FtpConnection1.GetFiles())
            FtpConnection1.Close()

        Catch ex As Exception
            If FtpConnection1.IsConnected Then
                FtpConnection1.Close()
            End If
            MessageBox.Show(Me, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try


- Hans (EnterpriseDT)
0 votes
by (260 points)
Thanks for the answer look forward to the new version and you never know if it works well i might get the company to purchase the pro version :)


p.s. just noticed i but this thread in the Java section not the .NET :lol:

Categories

...