CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
How do I selectively upload via FTP Win NT files?

 



hothat
Deleted

Mar 1, 2000, 1:09 PM

Post #1 of 3 (645 views)
How do I selectively upload via FTP Win NT files? Can't Post

Hello!
I have two related struggles with this code at the moment. First, I am attempting to PUT selective files to a remote site from a Win NT box. How do I read the desired local Win directory? Secondly, on my selection, I only want to upload those files that are 8 and only 8 digits for their filetitle -- my regexp needs polishing.

Here is the block of troublesome code:

my $file_put_regexp = "12345678";
#my $file_put_regexp = '\d\d\d\d\d\d\d\d';


chdir($local750_dir)
or log_msg("Couldn't change dir to $local750_dir: $!", 1);


my $ftp = Net::FTP->new($ftp_put_host, Passive=> $passive_mode, Debug => $debug_ftp);
log_msg("Couldn't start FTP client: $!",1) if !$ftp;
$ftp->login($username_put, $password_put)
or log_msg("Couldn't login as $username_put: $!",1);
$ftp->ascii
or log_msg("Couldn't specify ascii");
$ftp->quot($site750_put)
or log_msg("Couldn't specify $site750_put: $!" ,1);
# the listing command needs to go against the local750dir
$ftp->cwd($local750_dir)
or log_msg("Couldn't change FTP dir to $local750_dir: $!",1);
#my @listing = $ftp-> ls()
# or log_msg("Couldn't retrieve local file listing: $!", 1);
my $listing = readdir DIR;
my @files = grep(/$file_put_regexp/,@$listing);
log_msg("No files matching the 750 regexp $file_put_regexp were found",1) if !@files;
foreach $file (@files) {
$ftp->put($file)
or log_msg("Couldn't get $file: $!",1);
log_msg("Successfully placed $file");
#do housekeeping now and delete this file out of local750_dir, NOT the remotedir
$ftp->delete($file)
or log_msg("Couldn't delete $file: $!",1);
}
$ftp->quit();


This is my first post! I will look forward to any assistance that you can offer. Thanks.


darian
Deleted

Mar 2, 2000, 2:49 AM

Post #2 of 3 (645 views)
Re: How do I selectively upload via FTP Win NT files? [In reply to] Can't Post

Building a form like below should read the directory and allow you to choose which file you want to upload. As far as your regex, can't help there. I have to many problems with them myself.

<html>
<head>
<script language="Javascript">
<!-- Hide from old browsers
function validateFileEntry(validString, field) {
var isCharValid = true;
var i, invalidChar;
for (i=0; i<validString.length; i++) {
if (validString.charAt(0) == '.') {
isCharValid = false;
validString = validString.substr(1, validString.length-1);
i = validString.length;
}
if (validateCharacter(validString.charAt(i)) == false) {
isCharValid = false;
invalidChar = validString.charAt(i);
validString = validString.substr(0, i) + validString.substr(i+1, validString.length-1);
i = validString.length;
}
}
if (i < 1) { return false; }
if (isCharValid == false) {
if (invalidChar) alert("Invalid filename. Can't contain '" + invalidChar + "'. Filename adjusted.");
else alert('Invalid filename. Filename adjusted.');
if (field) {
field.value = validString;
field.focus();
field.select();
}
return false;
}
return true;
}

function serverFileName() {
var fileName = window.document.Upload.data.value.toLowerCase();
window.document.Upload.fn.value = fileName.substring(fileName.lastIndexOf("\\\\") + 1,fileName.length);
}
// -->
</script>
</head>
<body>

<form method=post action="upload.pl" NAME="Upload" ENCTYPE="multipart/form-data">
<input type=hidden name="action" value="upload">
<font color="black"><B>Upload a File:</B><br>
Local filename:
<INPUT NAME="data" TYPE="file" onBlur="serverFileName()"><br>
Remote filename:<br> <INPUT NAME="fn" onFocus="select()" onBlur="validateFileEntry(this.value, this)">
<input type="submit" value="Upload"></font>
</form>

[This message has been edited by darian (edited 03-02-2000).]


hothat
Deleted

Mar 2, 2000, 5:38 AM

Post #3 of 3 (645 views)
Re: How do I selectively upload via FTP Win NT files? [In reply to] Can't Post

Thank you Darian for your help. Your suggestion is very interesting, but in my particular case it won't work. What I'm dealing with (and I didn't make this too clear in my original question) is a non-interactive batch process. This Perl script will be initiated once every 24 hours to do two tasks: first, to do a "get" from a remote Win NT box. Then, with those 'gotten' files in a local directory, it will secondly, do a "Put" to yet another remote mainframe box.
Any ideas???

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives