Please don't top post. ------------------------------------------------ On Thu, 10 Jul 2003 18:42:45 -0600, "Gregg R. Allen" <[EMAIL PROTECTED]> wrote:
> > If you don't mind escaping to the shell, this is how I get a list of > files I want to ftp. > > > #This returns a list of files to be ftp'ed > my $files = `ls`; > > > #turn the files variable into an array of file names. > my @ftpfiles = split(/\n/ , $files); > > I won't say this is the "wrong" way to do it in so much as it gets the job done. It is probably the least efficient, most insecure, and most error prone way to do it. perldoc -f opendir perldoc -f readdir perldoc -f closedir perldoc File::Find If you are going to shell out please at least use a full path, check the return status, store the output to an array directly rather than splitting, and detaint the values. You *should* mind escaping to the shell unless it is an absolute must, in other words you have exhausted all other possibilities. Though I am also not sure which question of the OP this addressed. OP, Your question seems a bit odd about $Directory, can't that be set prior to calling the 'dir'? And you might consider a better name for @Directory possibly @RemoteFileList, so you end up with: my $Directory = '/path/to/directory'; my @RemoteFileList = $ftp->dir($Directory); That way your variables are more descriptive. Check the docs for Net::FTP for your long vs. short file list. In particular 'dir' gives you the long list, where 'ls' gives you the short one. So, my @RemoteFileList = $ftp->ls($Directory); As to your internal server error, are you printing the header? Also you have either a typo in the code or you should consider copying and pasting instead, as you have the following line: $my Directory; You are not checking to make sure 'open' worked. Sorry I didn't have the original post to provide inline comments. http://danconia.org > > > On Thursday, Jul 10, 2003, at 04:13 US/Mountain, Sara wrote: > > > #!/usr/bin/perl -w > > > > use strict; > > use warnings; > > use CGI::Carp 'fatalsToBrowser'; > > use CGI qw/:standard/; > > use Net::FTP; > > > > > > > > my $ftp = Net::FTP->new("ftp.yourserver.com", Debug => 0) > > or die "Cannot connect to some.host.name: $@"; > > > > $ftp->login("username",'password') > > or die "Cannot login ", $ftp->message; > > > > $ftp->cwd("/") > > or die "Cannot change working directory ", $ftp->message; > > > > my @Directory = $ftp->dir("/path/to/directory"); > > print "@Directory"; > > > > $ftp->quit; > > > > > > I am using the following to login to remote FTP; > > and its working fine and I am getting the list of files from remote > > FTP from my desired directory but; > > > > - The script is working fine in my Window IDE and giving an Internal > > Server Error (without any error message) while on my Host. > > > > - its returning @Directory in long format > > "-rw-r--r-- 1 username username 8654 Jul 5 18:20 test.html" > > Is it possible to get file names only like test.html > > > > > > and how to provide $Directory in the script given below because above > > is an array context @Directory? > > > > because after getting the list of files from the directory above I > > want to match/compare the file names with a text list on my server, > > see below..... > > > > ################################### > > $my Directory = "."; > > > > if ( open( NO, 'data.txt' ) ) > > { > > while ( <NO> ) > > { > > chomp; > > # Optional: Add check for blank/incomplete lines. > > > > if ( -f "$Directory/$_" ) > > { > > print "File '$_' exists in '$Directory'.\n"; > > # Optional: Add file to 'exists' list for later reporting. > > } > > else > > { > > print "File '$_' does NOT exist in '$Directory'.\n"; > > # Optional: Add file to 'not exists' list for later > > reporting. > > } > > } > > close( NO ); > > } > > else > > { > > print "ERROR: Unable to open file: $!\n"; > > } > > > > > > > > Thanks, > > > > SARA. > > > > > > > > > > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]