in reply to FTP and update files from a list
Celebrate Intellectual Diversity
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: FTP and update files from a list
by lev36 (Sexton) on Mar 28, 2006 at 02:09 UTC | |
It feels like homework, but it's work work. Anyway, I figured I would open the list of files and read them into an array. And please don't laugh, but I really am new to this language! I'm sure I'm missing some subtleties in what follows:
Then, I figured I'd iterate through the array and FTP the files to the working directory, which I don't yet know how to do. Next, I'd save off the .bak copies, doing something like this:
And finally, FTP the updated files back. | [reply] [d/l] [select] |
by Scrat (Monk) on Mar 28, 2006 at 05:39 UTC | |
Cheers Scrat | [reply] [d/l] |
by graff (Chancellor) on Mar 28, 2006 at 11:39 UTC | |
The "s///" operator will return true or false (1 or 0), and that is what the "print" function will get. Your output file will have a "0" or a "1" for each line of the input file, instead of the actual data. Also, you're likely to run this script more than once (since you probably won't get everything right the first time), so you probably want the edited versions of files to be in a different directory (keep the source files and source directory unchanged), and you surely don't want to open the output files with ">>$filename". Since perl gets used for this sort of thing a lot, there are a lot of short-cuts to make it easier. You could do the edit like this: As for the FTP part, if the remote machine is running an anonymous-ftp server, and the files in question are available that way, then Net::FTP is fine. But if you need to use a particular (non-anonymous) user account and a password, you really should use Net::SFTP. I would recommand that you keep the (S)FTP stuff in a separate script from the editing stuff. (It's actually more likely that you don't need a perl script at all to do the file transfers between machines, but if you want to make up a perl script to "reinvent" the existing (s)ftp programs, go ahead.) The point is that you can write a re-usable file-transfer script that will be handy for lots of occasions (assuming the standard tools are less handy), and you can even write a re-usable editing script for making changes to a list of files, which will be handy for lots of occasions (it is possible to provide a list of regex substitutions as an input). Both of these things are relatively easy. But if a script is going to do both file transfers and editing, that one script will be larger and more complicated and will take longer to write; and making it re-usable in any practical sense is going to be a lot more difficult. | [reply] [d/l] [select] |
|
Re^2: FTP and update files from a list
by lev36 (Sexton) on Mar 27, 2006 at 23:33 UTC | |
It's mainly the FTP part of the script I don't have a clue about. I'll post my meagre lines of script in the morning to (hopefully) prove my worthines... | [reply] |