diff options
author | jkh <jkh@FreeBSD.org> | 1995-04-25 15:05:11 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1995-04-25 15:05:11 +0000 |
commit | 02ace706173509b7d8549494277ff682b7cefb8a (patch) | |
tree | 437a6d909f192743fe7d26def0fdfae947754209 /lib/libftp/utils/mirror.c | |
download | FreeBSD-src-02ace706173509b7d8549494277ff682b7cefb8a.zip FreeBSD-src-02ace706173509b7d8549494277ff682b7cefb8a.tar.gz |
A programmatic interface to ftp. I need this for several other
components of the system.
The license is poorly worded, though I have an (email only) release
from the author for unlimited FreeBSD use. I will try to get something
more concrete, though the author's remote location makes this difficult.
Submitted by: Oleg Orel <orel@oea.ihep.su>
Diffstat (limited to 'lib/libftp/utils/mirror.c')
-rw-r--r-- | lib/libftp/utils/mirror.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/lib/libftp/utils/mirror.c b/lib/libftp/utils/mirror.c new file mode 100644 index 0000000..babd840 --- /dev/null +++ b/lib/libftp/utils/mirror.c @@ -0,0 +1,92 @@ + +/* Mirror directrory structure to another host */ + + +#include <stdio.h> +#include <sys/types.h> +#include <sys/dir.h> +#include <sys/stat.h> +#include <syslog.h> +#include <FtpLibrary.h> + +/* Usage: mirror <local_dir> <host> <user> <passwd> <remote_dir> */ +FTP *ftp; + +main(int a,char **b) +{ + +#define LOCAL_DIR b[1] +#define HOST b[2] +#define USER b[3] +#define PASSWD b[4] +#define REMOTE_DIR b[5] + + if ( a < 5 ) + quit("Usage: mirror <local_dir> <host> <user> <passwd> <remote_dir>"); + + + FtplibDebug(yes); + FtpLogin(&ftp,HOST,USER,PASSWD,NULL); + FtpChdir(ftp,REMOTE_DIR); + FtpBinary(ftp); + doit(LOCAL_DIR); + exit(0); +} + +doit(char *dirname) +{ + DIR *dp; + struct direct *de; + char n[256],fn[256]; + struct stat st; + + + if ( (dp=opendir(dirname)) == NULL ) + { + log(dirname); + return; + } + + while ( (de = readdir(dp)) != NULL ) + { + if ( de -> d_name[0] == '.' ) + continue; + + sprintf(fn,"%s/%s",dirname,de->d_name); + + if ( stat(fn,&st) != 0 ) { + log(fn); + continue; + } + + if ( S_ISDIR (st.st_mode) ) + { + FtpCommand(ftp,"MKD %s",fn,0,EOF); /* Ignore errors (0,EOF) */ + doit(fn); + continue; + } + + if ( st.st_size != FtpSize(ftp,fn)) + + FtpPut(ftp,fn,fn); + } + + closedir(dp); + +} + + + +quit(char *s) +{ + log(s); + exit(1); +} + +log(char *s) +{ + perror(s); +} + + + |