Skip to main content
gamedev.net
🔒 Locked

FTP Scripting

Started by CWizard Sep 10, 2003 at 5:53 PM 5 replies 1.3k views
Original Post
CWizard
CWizard
I''m sorry I have to bother you guys, but it seems I need some pointers here. I am working on a simple remote backup solutions, where the source machine (call it server) regulary makes a backup and stores it locally. Another, remote, machine (call it client) would then regulary, at its discretion, probe the source machine and download any new backups. I could invent some specialized protocol for this, but it seems much better to use FTP. The source machine just runs a regular FTP server with an account to allow access to the backup files. However, on the other side its more problematic. There is no guarantee that the client machine is available at any single time and it might need to shutdown during transfer, and as backups might be really big (10+ GB) it would be essential that it can resume the download, and be killed without corrupting data. I will, of course, not do any of this in C or similar, but rather my beloved Perl, and it must be cross-platform (at least Linux and Windows). So, the question comes down to: what package/library/program would be appropriate to use for the FTP client functionality? I have tried googling, but I am hard pressed to find something that looks "standard"/reliable and/or fulfills my requirements. Any pointers or ideas are welcomed.
CWizard
CWizard
Gah, I did probably came up with the solution. I''ve been pondering this problem for some weeks, thinking about some command-line tool, without thinking of the obvious: Perl modules. In this case Net::FTP, which will probably do the trick.

Ideas/comments are still welcomed, however.
Dwiel
Dwiel
If there is no logic statements and no jumps or loops or anything, you can use the ftp command to runa script. Use this syntax:

ftp -n -i -s:filename servname

I found this satisfactory for running simple scripts. I would really like to create a program, preferably commandline, that, given a servername, login/pass info, and a remote folder, would download every file onto a specified place onto your HD. It would also be nice to be able to set a retry time, and be able to connect to multipule servers at once. I''d love to hear how you are accomplishing your goals because it might allow me to accomplish mine in a more elegent way. Thank you.

Dwiel
CWizard
CWizard
There are unfortunately some logic required, as in my case I will use the filesystem as the "protocol interface". I investigated the ftp command, but I couldn't manage to control it correctly from my script (EDIT: ie. piping commands to it), and it didn't seem to support resuming downloads.

But, take a look at the Perl module I mentioned, Net::FTP. As its synopsis will let us know, it is as simple as:

use Net::FTP;

$ftp = Net::FTP->new("some.host.name", Debug => 0);
$ftp->login("anonymous",'-anonymous@');
$ftp->cwd("/pub");
$ftp->get("that.file");
$ftp->quit;
Using this module, I think one should be able to hack up your idea in a couple of minutes.

[edited by - CWizard on September 10, 2003 8:29:51 PM]
Dwiel
Dwiel
Thank you a ton!!! This is exactly what I wanted! Good thing I learned Perl over the summer (ie 2 days lol) This will be much better than the code I was trying to write in C/C++. Thank you a ton. I''ll try it and let you know what I come up with as soon as I get my homework done.

BTW, I found this little tutorial which looks good: tutorial found here

Dwiel
C-Junkie
C-Junkie
Hi, ever heard of rsync? you''re reinventing the wheel.
CWizard
CWizard
quote:
Original post by C-Junkie
Hi, ever heard of rsync? you''re reinventing the wheel.
I have, and use it too. In this case, however, it is not applicable, since the server and client(s) needs to be asynhronous. In this case, I would need to build huge and complex wrappers around rsync for it to behave as necessary.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.