chamberlain2007
Programmer
- Apr 29, 2007
- 1
Hello, I'm writing a simple FTP client in Perl-Gtk2. The function that I'm having a problem with is downloading the file. Have a look at this code.
$list->signal_connect('button-press-event' =>
sub {
my @selected = $list->get_selected_indices;
my $menu = Gtk2::Menu->new();
my $menuitem1 = Gtk2::MenuItem->new("Get file");
my $menuitem2 = Gtk2::MenuItem->new("Switch directory");
$menuitem1->signal_connect(activate => \&getfile, @selected);
$menuitem2->signal_connect(activate => sub { print "Clicked2"; } );
$menuitem1->show();
$menuitem2->show();
$menu->append($menuitem1);
$menu->append($menuitem2);
my ($widget, $event) = @_;
return FALSE unless $event->button == 3;
$menu->popup(
undef,
undef,
undef,
undef,
$event->button,
$event->time);
}
);
sub getfile {
my $host = $host_enter->get_text();
my $conn = Net::FTP->new($host, Debug => 0)
or &dienice("$@");
my $user = $user_enter->get_text();
my $pass = $pass_enter->get_text();
$conn->login($user, $pass)
or &dienice($conn->message);
$conn->cwd("wlan")
or &dienice($conn->message);
my (undef, @see) = @_;
foreach my $q (@see) {
my $w = $list->{data}->[$q]->[0];
print "Downloading file $w\n";
$conn->get($w);
print "Got file $w\n";
return;
}
return;
}
What it is supposed to do is download the selected file when the user clicks on the "Get File" option on the context menu. The problem is that it doesn't download he file until the use clicks on the "Get file" option for a second time. If someone knows why this might be happening, lease let me know!
$list->signal_connect('button-press-event' =>
sub {
my @selected = $list->get_selected_indices;
my $menu = Gtk2::Menu->new();
my $menuitem1 = Gtk2::MenuItem->new("Get file");
my $menuitem2 = Gtk2::MenuItem->new("Switch directory");
$menuitem1->signal_connect(activate => \&getfile, @selected);
$menuitem2->signal_connect(activate => sub { print "Clicked2"; } );
$menuitem1->show();
$menuitem2->show();
$menu->append($menuitem1);
$menu->append($menuitem2);
my ($widget, $event) = @_;
return FALSE unless $event->button == 3;
$menu->popup(
undef,
undef,
undef,
undef,
$event->button,
$event->time);
}
);
sub getfile {
my $host = $host_enter->get_text();
my $conn = Net::FTP->new($host, Debug => 0)
or &dienice("$@");
my $user = $user_enter->get_text();
my $pass = $pass_enter->get_text();
$conn->login($user, $pass)
or &dienice($conn->message);
$conn->cwd("wlan")
or &dienice($conn->message);
my (undef, @see) = @_;
foreach my $q (@see) {
my $w = $list->{data}->[$q]->[0];
print "Downloading file $w\n";
$conn->get($w);
print "Got file $w\n";
return;
}
return;
}
What it is supposed to do is download the selected file when the user clicks on the "Get File" option on the context menu. The problem is that it doesn't download he file until the use clicks on the "Get file" option for a second time. If someone knows why this might be happening, lease let me know!