home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d1xx
/
d145
/
dnet.lha
/
Dnet
/
amiga
/
client
/
putfiles.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-05-26
|
4KB
|
188 lines
/*
* PUTFILES.C
*
* DNET (c)Copyright 1988, Matthew Dillon, All Rights Reserved.
*
* Download one or more files or directories to the remote host
*/
#include <stdio.h>
#include "/server/servers.h"
int Enable_Abort;
char Buf[1024];
typedef struct FileInfoBlock FIB;
extern char *AllocMem();
main(ac,av)
char *av[];
{
long chan;
long n, len, orig;
long fh;
short i, j;
char fn;
char *host = NULL;
if (ac == 1) {
puts("putfiles [-Nnet#] [-dremotedir] file/dir file/dir ....");
exit(1);
}
Enable_Abort = 0;
if (ac > 1 && strncmp(av[1], "-N", 2) == 0) {
host = av[1] + 2;
--ac;
++av;
}
chan = DOpen(host, PORT_FILECOPY, -80, 126);
if (!chan) {
puts("Unable to connect");
exit(1);
}
DRead(chan, &fn, 1);
if (fn != 'Y') {
puts("Remote Server Software Error");
DClose(chan);
exit(1);
}
for (i = 1; i < ac; ++i) {
if (strncmp(av[i], "-d", 2) == 0) {
char *dir = av[i] + 2;
if (*dir == 0 && i+1 < ac) {
++i;
dir = av[i];
}
if (writehdr(chan, 'C', dir, 0) != 'Y') {
printf("Unable to go to remote directory %s\n", dir);
break;
}
} else {
if (putname(chan, av[i]) < 0)
break;
}
}
printf("\nclosing... ");
fflush(stdout);
DClose(chan);
puts("done");
}
putname(chan, file)
char *file;
{
long lock = Lock(file, SHARED_LOCK);
long dirl;
int ret = 1;
FIB *fib = (FIB *)AllocMem(sizeof(FIB), MEMF_PUBLIC);
printf("%-20s ", file);
if (lock == NULL || !Examine(lock, fib)) {
FreeMem(fib, sizeof(FIB));
puts("NOT FOUND");
return(1);
}
if (fib->fib_DirEntryType > 0) {
char *dirname = (fib->fib_FileName[0]) ? fib->fib_FileName : "ram";
puts("DIR");
dirl = CurrentDir(lock);
if (writehdr(chan, 'X', dirname, 0) != 'Y') {
puts("Remote unable to make directory");
goto f1;
}
while (ExNext(lock, fib)) {
if (putname(chan, fib->fib_FileName) < 0) {
ret = -1;
break;
}
}
writehdr(chan, 'Y', "?", 0);
f1:
UnLock(CurrentDir(dirl));
} else {
UnLock(lock);
ret = putfile(chan, file, fib->fib_FileName);
}
FreeMem(fib, sizeof(FIB));
return(ret);
}
putfile(chan, file, stripedname)
char *file;
char *stripedname;
{
long fh = Open(file, 1005);
long n, r, len;
long ttl = 0;
char co;
fflush(stdout);
if (fh == NULL) {
puts("FILE NOT FOUND");
return(0);
}
Seek(fh, 0, 1);
len = ttl = Seek(fh, 0, -1);
if (writehdr(chan, 'W', stripedname, len) != 'Y') {
puts("REMOTE UNABLE TO ACCEPT FILE");
Close(fh);
return(0);
}
printf("%6ld/%-6ld", ttl - len, ttl);
while (len) {
fflush(stdout);
r = (len > sizeof(Buf)) ? sizeof(Buf) : len;
n = Read(fh, Buf, r);
if (n != r) {
puts("Local File error");
Close(fh);
return(-1);
}
if (DWrite(chan, Buf, n) != n) {
puts("Remote error");
Close(fh);
return(-1);
}
if (SetSignal(0,0) & SIGBREAKF_CTRL_C) {
puts("\nBreak");
Close(fh);
return(-1);
}
len -= n;
printf("\010\010\010\010\010\010\010\010\010\010\010\010\010");
printf("%6ld/%-6ld", ttl - len, ttl);
}
Close(fh);
if (len) {
puts("REMOTE ERROR");
return(-1);
}
printf("Queued, waiting...");
fflush(stdout);
DRead(chan, &co, 1);
if (co != 'Y') {
puts("Remote Server Software Error");
return(-1);
}
puts(" OK");
return(0);
}
writehdr(chan, c, name, len)
unsigned char c;
char *name;
long len;
{
DWrite(chan, &c, 1);
c = strlen(name) + 1;
DWrite(chan, &c, 1);
DWrite(chan, name, c);
DWrite(chan, &len, 4);
if (DRead(chan, &c, 1) == 1)
return(c);
return(-1);
}