Beispiel #1
0
int
FTPPutOneFile3(
	const FTPCIPtr cip,
	const char *const file,
	const char *const dstfile,
	const int xtype,
	const int fdtouse,
	const int appendflag,
	const char *const tmppfx,
	const char *const tmpsfx,
	const int resumeflag,
	const int deleteflag,
	const FTPConfirmResumeUploadProc resumeProc,
	int UNUSED(reserved))
{
	int result;

	LIBNCFTP_USE_VAR(reserved);
	if (cip == NULL)
		return (kErrBadParameter);
	if (strcmp(cip->magic, kLibraryMagic))
		return (kErrBadMagic);
	
	if ((dstfile == NULL) || (dstfile[0] == '\0'))
		return (kErrBadParameter);
	if (fdtouse < 0) {
		if ((file == NULL) || (file[0] == '\0'))
			return (kErrBadParameter);
	}
	result = FTPPutOneF(cip, file, dstfile, xtype, fdtouse, appendflag, tmppfx, tmpsfx, resumeflag, deleteflag, resumeProc);
	return (result);
}	/* FTPPutOneFile3 */
Beispiel #2
0
void
ErrorHook(const FTPCIPtr UNUSED(cipUnused), char *msg)
{
	LIBNCFTP_USE_VAR(cipUnused);		/* shut up gcc */

	/* Will also get Trace'd. */
	(void) fprintf(stdout, "%s", msg);
}	/* ErrorHook */
Beispiel #3
0
/*ARGSUSED*/
static void
SigIntHostWin(int UNUSED(sig))
{
	LIBNCFTP_USE_VAR(sig);
	alarm(0);
#ifdef HAVE_SIGSETJMP
	siglongjmp(gHostWinJmp, 1);
#else	/* HAVE_SIGSETJMP */
	longjmp(gHostWinJmp, 1);
#endif	/* HAVE_SIGSETJMP */
}	/* SigIntHostWin */
Beispiel #4
0
int
UnMlsT(const FTPCIPtr UNUSED(cip), const char *const line0, const MLstItemPtr mlip)
{
	char *cp, *val, *fact;
	int ec;
	size_t len;
	char line[1024];

	LIBNCFTP_USE_VAR(cip);
	memset(mlip, 0, sizeof(MLstItem));
	mlip->mode = -1;
	mlip->fsize = kSizeUnknown;
	mlip->ftype = '-';
	mlip->ftime = kModTimeUnknown;

	len = strlen(line0);
	if (len > (sizeof(line) - 1))
		return (-1);	/* Line too long, sorry. */
	/* This should be re-coded so does not need to make a
	 * copy of the buffer; it could be done in place.
	 */
	memcpy(line, line0, len + 1);

	/* Skip leading whitespace. */
	for (cp = line; *cp != '\0'; cp++) {
		if (! isspace((int) *cp))
			break;
	}

	while (*cp != '\0') {
		for (fact = cp; ; cp++) {
			if ((*cp == '\0') || (*cp == ' ')) {
				/* protocol violation */
				return (-1);
			}
			if (*cp == '=') {
				/* End of fact name. */
				*cp++ = '\0';
				break;
			}
		}
		for (val = cp; ; cp++) {
			if (*cp == '\0') {
				/* protocol violation */
				return (-1);
			}
			if (*cp == ' ') {
				ec = ' ';
				*cp++ = '\0';
				break;
			} else if (*cp == ';') {
				if (cp[1] == ' ') {
					ec = ' ';
					*cp++ = '\0';
					*cp++ = '\0';
				} else {
					ec = ';';
					*cp++ = '\0';
				}
				break;
			}
		}
		if (ISTRNEQ(fact, "OS.", 3))
			fact += 3;
		if (ISTREQ(fact, "type")) {
			if (ISTREQ(val, "file")) {
				mlip->ftype = '-';
			} else if (ISTREQ(val, "dir")) {
				mlip->ftype = 'd';
			} else if (ISTREQ(val, "cdir")) {
				/* not supported: current directory */
				return (-2);
			} else if (ISTREQ(val, "pdir")) {
				/* not supported: parent directory */
				return (-2);
			} else {
				/* ? */
				return (-1);
			}
		} else if (ISTREQ(fact, "UNIX.mode")) {
			if (val[0] == '0')
				sscanf(val, "%o", &mlip->mode);
			else	
				sscanf(val, "%i", &mlip->mode);
			if (mlip->mode != (-1))
				mlip->mode &= 00777;
		} else if (ISTREQ(fact, "perm")) {
			STRNCPY(mlip->perm, val);
		} else if (ISTREQ(fact, "size")) {
#if defined(HAVE_LONG_LONG) && defined(SCANF_LONG_LONG)
			(void) sscanf(val, SCANF_LONG_LONG, &mlip->fsize);
#elif defined(HAVE_LONG_LONG) && defined(HAVE_STRTOQ)
			mlip->fsize = (longest_int) strtoq(val, NULL, 0);
#else
			{
				long fsize2 = 0L;

				(void) sscanf(val, "%ld", &fsize2);
				mlip->fsize = (longest_int) fsize2;
			}
#endif
		} else if (ISTREQ(fact, "modify")) {
			mlip->ftime = UnMDTMDate(val);
		} else if (ISTREQ(fact, "UNIX.owner")) {
			STRNCPY(mlip->owner, val);
		} else if (ISTREQ(fact, "UNIX.group")) {
			STRNCPY(mlip->group, val);
		} else if (ISTREQ(fact, "UNIX.uid")) {
			mlip->uid = atoi(val);
		} else if (ISTREQ(fact, "UNIX.gid")) {
			mlip->gid = atoi(val);
		} else if (ISTREQ(fact, "perm")) {
			STRNCPY(mlip->perm, val);
		}

		/* End of facts? */
		if (ec == ' ')
			break;
	}

	len = strlen(cp);
	if (len > (sizeof(mlip->fname) - 1)) {
		/* Filename too long */
		return (-1);
	}
	memcpy(mlip->fname, cp, len);

	/* also set linkto here if used */

	return (0);
}	/* UnMlsT */
Beispiel #5
0
int
FTPPutFiles3(
    const FTPCIPtr cip,
    const char *const pattern,
    const char *const dstdir1,
    const int recurse,
    const int doGlob,
    const int xtype,
    int appendflag,
    const char *const tmppfx,
    const char *const tmpsfx,
    const int resumeflag,
    const int deleteflag,
    const FTPConfirmResumeUploadProc resumeProc,
    int UNUSED(reserved))
{
    FTPLineList globList;
    FTPFileInfoList files;
    FTPFileInfoPtr filePtr;
    int batchResult;
    int result;
    const char *dstdir;
    char dstdir2[512];

    LIBNCFTP_USE_VAR(reserved);
    if (cip == NULL)
        return (kErrBadParameter);
    if (strcmp(cip->magic, kLibraryMagic))
        return (kErrBadMagic);

    if (dstdir1 == NULL)
    {
        dstdir = NULL;
    }
    else
    {
        dstdir = STRNCPY(dstdir2, dstdir1);
        StrRemoveTrailingLocalPathDelim(dstdir2);
    }

    (void) FTPLocalGlob(cip, &globList, pattern, doGlob);
    if (recurse == kRecursiveYes)
    {
        appendflag = kAppendNo;
        (void) FTPLocalRecursiveFileList(cip, &globList, &files);
        if (files.first == NULL)
        {
            cip->errNo = kErrNoValidFilesSpecified;
            return (kErrNoValidFilesSpecified);
        }
        (void) ComputeRNames(&files, dstdir, 0, 1);
    }
    else
    {
        (void) LineListToFileInfoList(&globList, &files);
        (void) ComputeLNames(&files, NULL, NULL, 1);
        (void) ComputeRNames(&files, dstdir, 0, 0);
    }
    DisposeLineListContents(&globList);

#if 0
    for (filePtr = files.first; filePtr != NULL; filePtr = filePtr->next)
    {
        PrintF(cip, "  R=%s, L=%s, 2=%s, size=%lld, mdtm=%u, type=%c\n",
               filePtr->rname,
               filePtr->lname,
               filePtr->rlinkto ? filePtr->rlinkto : "",
               filePtr->size,
               (unsigned int) filePtr->mdtm,
               filePtr->type
              );
    }
#endif

    batchResult = kNoErr;
    for (filePtr = files.first; filePtr != NULL; filePtr = filePtr->next)
    {
        if (cip->connected == 0)
        {
            if (batchResult == kNoErr)
                batchResult = kErrRemoteHostClosedConnection;
            break;
        }
        if (filePtr->type == 'd')
        {
            /* mkdir */
            StrRemoveTrailingLocalPathDelim(filePtr->rname);
            result = FTPMkdir(cip, filePtr->rname, kRecursiveNo);
            if (result != kNoErr)
                batchResult = result;
#ifdef HAVE_SYMLINK
        }
        else if (filePtr->type == 'l')
        {
            /* symlink */
            /* no RFC way to create the link, though. */
            if ((filePtr->rlinkto != NULL) && (filePtr->rlinkto[0] != '\0'))
                (void) FTPSymlink(cip, filePtr->rname, filePtr->rlinkto);
#endif
        }
        else if (recurse != kRecursiveYes)
        {
            result = FTPPutOneF(cip, filePtr->lname, filePtr->rname, xtype, -1, appendflag, tmppfx, tmpsfx, resumeflag, deleteflag, resumeProc);
            if (files.nFileInfos == 1)
            {
                if (result != kNoErr)
                    batchResult = result;
            }
            else
            {
                if ((result != kNoErr) && (result != kErrLocalFileNewer) && (result != kErrRemoteFileNewer) && (result != kErrRemoteSameAsLocal))
                    batchResult = result;
            }
            if (result == kErrUserCanceled)
                cip->cancelXfer = 1;
            if (cip->cancelXfer > 0)
                break;
        }
        else
        {
            result = FTPPutOneF(cip, filePtr->lname, filePtr->rname, xtype, -1, appendflag, tmppfx, tmpsfx, resumeflag, deleteflag, resumeProc);
            if (files.nFileInfos == 1)
            {
                if (result != kNoErr)
                    batchResult = result;
            }
            else
            {
                if ((result != kNoErr) && (result != kErrLocalFileNewer) && (result != kErrRemoteFileNewer) && (result != kErrRemoteSameAsLocal))
                    batchResult = result;
            }
            if (result == kErrUserCanceled)
                cip->cancelXfer = 1;
            if (cip->cancelXfer > 0)
                break;
        }
    }
    DisposeFileInfoListContents(&files);
    if (batchResult < 0)
        cip->errNo = batchResult;
    return (batchResult);
}	/* FTPPutFiles3 */
Beispiel #6
0
void
DebugHook(const FTPCIPtr UNUSED(cipUnused), char *msg)
{
	LIBNCFTP_USE_VAR(cipUnused);		/* shut up gcc */
	Trace(0, "%s", msg);
}	/* DebugHook */