Gossamer Forum
Home : General : Perl Programming :

getting files

Quote Reply
getting files
i forgot how to do this. I need some help.
If i had on one server a file or multiple files setup up as a backup for another server with the files that have the same names, how would i with the click of a button, take all the files at once from the backup and use them to replace the main servers files.
For example, i have a database, and someone messes with it but i want to restore it without like uploading the original by ftp.

Quote Reply
Re: getting files In reply to
You can use Net::FTP
Code:
$ftp = Net::FTP->new("http://www.bla.com")
$ftp->login("bla", "bla");
$ftp->cd("/path/to/bla");
$ftp->get("blah.backup");
$ftp->quit;
(or whatever)



Installations:http://www.wiredon.net/gt/

Quote Reply
Re: getting files In reply to
That looks like it could work but i'm not sure by looking at the gzip part. I make an example using a links reference
I have links.db, categories.db and the other dbs at url.hypermart.net, just there as plain files. I have my main site with those files located in the data folder. When i let someone into my admin, i want them to view and change and look at stuff but in case they delete all the links and categories, i want there to be a link in the admin so that when ever i or another user pushes it, it will restore the files by taking the links.db, categories.db etc... from the url.hypermart.net site and use them to replace the ones in my data folder. So basically like a copy and paste, but copy from one server, and paste to another server over an existing file.
Thanks Paul

Quote Reply
Re: getting files In reply to
Ok....

Code:
#!/usr/bin/perl
Code:
use CGI qw(:standard);
Code:
eval { &main; };
if ($@) {
print "Content-type: text/plain\n\n";
print $@;
exit;
}
Code:
sub main {
$local = "/path/to/local/data/dir/";
$remote = "/path/to/data/dir/";
$ftp = Net::FTP->new("ftp://ftp.hypermart.net") || &error($!);
$ftp->login("USERNAME", "PASSWORD") || &error($!);
$ftp->cwd($remote) || &error($!);
$ftp->get("links.db", "links.db", $local) || &error($!);
$ftp->get("url.db", "url.db", $local) || &error($!);
$ftp->get("email.db", "email.db", $local) || &error($!);
$ftp->get("validate.db", "validate.db", $local) || &error($!);
$ftp->get("linksid.txt", "linksid.txt", $local) || &error($!);
$ftp->get("category.db", "category.db", $local) || &error($!);
$ftp->get("categoryid.txt", "categoryid.txt", $local) || &error($!);
$ftp->quit;
Code:
print header;
print "Done!";
}
Code:
sub error {
my ($msg) = shift;
print header;
print $msg;
exit;
}
You may be able to do it a quicker way but that should work.

Installations:http://www.wiredon.net/gt/

Quote Reply
Re: getting files In reply to
thank you very much Paul


Quote Reply
Re: getting files In reply to
No problem.

Just another point....you can set the transfer mode and chmod the files also using:

Code:
$ftp->type("A");
(ascii)

Code:
$ftp->site("chmod 0777 filename");
A quick way to get all the files in your data directory would be...

Code:
@files = $ftp->ls();
foreach $file (@files) {
$ftp->get($file);
}
I'm not sure I got the *get* syntax right.

Code:
$ftp->get("filename");
...works....but I'm not sure about the syntax I gave, but give it a try.

Anyway I'm rambling Smile

Installations:http://www.wiredon.net/gt/