ReactOS 0.4.15-dev-7958-gcd0bb1a
ncftp.h File Reference
#include <stdio.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "ncftp_errno.h"
Include dependency graph for ncftp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Line
 
struct  LineList
 
struct  Response
 
struct  SReadlineInfo
 
struct  FTPLibraryInfo
 
struct  FTPConnectionInfo
 
struct  FileInfo
 
struct  FileInfoList
 
struct  MLstItem
 

Macros

#define kLibraryVersion   "@(#) LibNcFTP 3.0.6 (April 14, 2001)"
 
#define USE_SIO   1
 
#define NO_SIGNALS   1
 
#define kLibraryMagic   "LibNcFTP 3.0.6"
 
#define longest_int   long long
 
#define longest_uint   unsigned long long
 
#define forever   for ( ; ; )
 
#define _SReadlineInfo_   1
 
#define kPrInitMsg   1
 
#define kPrUpdateMsg   2
 
#define kPrEndMsg   3
 
#define kSendPortMode   0
 
#define kPassiveMode   1
 
#define kFallBackToSendPortMode   2
 
#define kAcceptForWriting   00100
 
#define kAcceptForReading   00101
 
#define kNetWriting   kAcceptForWriting
 
#define kNetReading   kAcceptForReading
 
#define kResponseNoPrint   00001
 
#define kResponseNoSave   00002
 
#define kResponseNoProc   00002
 
#define kDefaultFTPPort   21
 
#define kDefaultFTPBufSize   32768
 
#define kDefaultXferTimeout   600
 
#define kDefaultConnTimeout   30
 
#define kDefaultCtrlTimeout   135
 
#define kDefaultAbortTimeout   10
 
#define kSuggestedDefaultXferTimeout   (0) /* No timeout on data blocks. */
 
#define kSuggestedDefaultConnTimeout   30
 
#define kSuggestedDefaultCtrlTimeout   135 /* 2*MSL, + slop */
 
#define kSuggestedAbortTimeout   10
 
#define kDefaultMaxDials   3
 
#define kDefaultRedialDelay   20 /* seconds */
 
#define kDefaultDataPortMode   kSendPortMode
 
#define kRedialStatusDialing   0
 
#define kRedialStatusSleeping   1
 
#define INADDR_NONE   (0xffffffff) /* <netinet/in.h> should have it. */
 
#define kTypeAscii   'A'
 
#define kTypeBinary   'I'
 
#define kTypeEbcdic   'E'
 
#define kGlobChars   "[*?"
 
#define GLOBCHARSINSTR(a)   (strpbrk(a, kGlobChars) != NULL)
 
#define kGlobYes   1
 
#define kGlobNo   0
 
#define kRecursiveYes   1
 
#define kRecursiveNo   0
 
#define kAppendYes   1
 
#define kAppendNo   0
 
#define kResumeYes   1
 
#define kResumeNo   0
 
#define kDeleteYes   1
 
#define kDeleteNo   0
 
#define kTarYes   1
 
#define kTarNo   0
 
#define UNIMPLEMENTED_CMD(a)   ((a == 500) || (a == 502) || (a == 504))
 
#define kSizeUnknown   ((longest_int) (-1))
 
#define kModTimeUnknown   ((time_t) (-1))
 
#define kCommandAvailabilityUnknown   (-1)
 
#define kCommandAvailable   1
 
#define kCommandNotAvailable   0
 
#define kNotURL   (-1)
 
#define kMalformedURL   (-2)
 
#define kFirewallNotInUse   0
 
#define kFirewallUserAtSite   1
 
#define kFirewallLoginThenUserAtSite   2
 
#define kFirewallSiteSite   3
 
#define kFirewallOpenSite   4
 
#define kFirewallUserAtUserPassAtPass   5
 
#define kFirewallFwuAtSiteFwpUserPass   6
 
#define kFirewallUserAtSiteFwuPassFwp   7
 
#define kFirewallLastType   kFirewallUserAtSiteFwuPassFwp
 
#define kPreferredMlsOpts   (kMlsOptType | kMlsOptSize | kMlsOptModify | kMlsOptUNIXmode | kMlsOptUNIXowner | kMlsOptUNIXgroup | kMlsOptUNIXuid | kMlsOptUNIXgid | kMlsOptPerm)
 
#define kMlsOptType   00001
 
#define kMlsOptSize   00002
 
#define kMlsOptModify   00004
 
#define kMlsOptUNIXmode   00010
 
#define kMlsOptUNIXowner   00020
 
#define kMlsOptUNIXgroup   00040
 
#define kMlsOptPerm   00100
 
#define kMlsOptUNIXuid   00200
 
#define kMlsOptUNIXgid   00400
 
#define kMlsOptUnique   01000
 
#define kFtwFile   0
 
#define kFtwDir   1
 
#define kChdirOnly   00000
 
#define kChdirAndMkdir   00001
 
#define kChdirAndGetCWD   00002
 
#define kChdirOneSubdirAtATime   00004
 
#define kConfirmResumeProcNotUsed   0
 
#define kConfirmResumeProcSaidSkip   1
 
#define kConfirmResumeProcSaidResume   2
 
#define kConfirmResumeProcSaidOverwrite   3
 
#define kConfirmResumeProcSaidAppend   4
 
#define kConfirmResumeProcSaidBestGuess   5
 
#define kConfirmResumeProcSaidCancel   6
 
#define NoConfirmResumeDownloadProc   ((ConfirmResumeDownloadProc) 0)
 
#define NoConfirmResumeUploadProc   ((ConfirmResumeUploadProc) 0)
 
#define NoGetPassphraseProc   ((FTPGetPassphraseProc) 0)
 
#define kServerTypeUnknown   0
 
#define kServerTypeWuFTPd   1
 
#define kServerTypeNcFTPd   2
 
#define kServerTypeProFTPD   3
 
#define kServerTypeMicrosoftFTP   4
 
#define kServerTypeWarFTPd   5
 
#define kServerTypeServ_U   6
 
#define kServerTypeWFTPD   7
 
#define kServerTypeVFTPD   8
 
#define kServerTypeFTP_Max   9
 
#define kServerTypeRoxen   10
 
#define kServerTypeNetWareFTP   11
 
#define kServerTypeWS_FTP   12
 
#define closesocket   close
 
#define ioctlsocket   ioctl
 
#define LOCAL_PATH_DELIM   '/'
 
#define LOCAL_PATH_DELIM_STR   "/"
 
#define StrFindLocalPathDelim(a)   strchr(a, LOCAL_PATH_DELIM)
 
#define StrRFindLocalPathDelim(a)   strrchr(a, LOCAL_PATH_DELIM)
 
#define StrRemoveTrailingLocalPathDelim   StrRemoveTrailingSlashes
 
#define IsLocalPathDelim(c)   (c == LOCAL_PATH_DELIM)
 
#define TVFSPathToLocalPath(s)
 
#define LocalPathToTVFSPath(s)
 
#define LIBNCFTP_USE_VAR(a)   gLibNcFTP_Uses_Me_To_Quiet_Variable_Unused_Warnings = (a == 0)
 
#define UNUSED(a)   a
 
#define NcSignal   signal
 

Typedefs

typedef void(* FTPSigProc) (int)
 
typedef struct LineLinePtr
 
typedef struct Line Line
 
typedef struct LineList LineList
 
typedef struct LineListLineListPtr
 
typedef struct Response Response
 
typedef struct ResponseResponsePtr
 
typedef struct SReadlineInfo SReadlineInfo
 
typedef struct FTPLibraryInfo FTPLibraryInfo
 
typedef struct FTPLibraryInfoFTPLIPtr
 
typedef struct FTPConnectionInfoFTPCIPtr
 
typedef void(* FTPProgressMeterProc) (const FTPCIPtr, int)
 
typedef void(* FTPLogProc) (const FTPCIPtr, char *)
 
typedef void(* FTPConnectMessageProc) (const FTPCIPtr, ResponsePtr)
 
typedef void(* FTPLoginMessageProc) (const FTPCIPtr, ResponsePtr)
 
typedef void(* FTPRedialStatusProc) (const FTPCIPtr, int, int)
 
typedef void(* FTPPrintResponseProc) (const FTPCIPtr, ResponsePtr)
 
typedef int(* FTPFtwProc) (const FTPCIPtr cip, const char *fn, int flag)
 
typedef void(* FTPGetPassphraseProc) (const FTPCIPtr, LineListPtr pwPrompt, char *pass, size_t dsize)
 
typedef struct FTPConnectionInfo FTPConnectionInfo
 
typedef struct FileInfoFileInfoPtr
 
typedef struct FileInfo ** FileInfoVec
 
typedef struct FileInfo FileInfo
 
typedef struct FileInfoList FileInfoList
 
typedef struct FileInfoListFileInfoListPtr
 
typedef struct MLstItem MLstItem
 
typedef struct MLstItemMLstItemPtr
 
typedef int(* ConfirmResumeDownloadProc) (const char *volatile *localpath, volatile longest_int localsize, volatile time_t localmtime, const char *volatile remotepath, volatile longest_int remotesize, volatile time_t remotetime, volatile longest_int *volatile startPoint)
 
typedef int(* ConfirmResumeUploadProc) (const char *volatile localpath, volatile longest_int localsize, volatile time_t localmtime, const char *volatile *remotepath, volatile longest_int remotesize, volatile time_t remotetime, volatile longest_int *volatile startPoint)
 

Functions

void FTPAbortDataTransfer (const FTPCIPtr cip)
 
int FTPChdir (const FTPCIPtr cip, const char *const cdCwd)
 
int FTPChdirAndGetCWD (const FTPCIPtr cip, const char *const cdCwd, char *const newCwd, const size_t newCwdSize)
 
int FTPChdir3 (FTPCIPtr cip, const char *const cdCwd, char *const newCwd, const size_t newCwdSize, int flags)
 
int FTPChmod (const FTPCIPtr cip, const char *const pattern, const char *const mode, const int doGlob)
 
int FTPCloseHost (const FTPCIPtr cip)
 
int FTPCmd (const FTPCIPtr cip, const char *const cmdspec,...)
 
int FTPDecodeURL (const FTPCIPtr cip, char *const url, LineListPtr cdlist, char *const fn, const size_t fnsize, int *const xtype, int *const wantnlst)
 
int FTPDelete (const FTPCIPtr cip, const char *const pattern, const int recurse, const int doGlob)
 
int FTPFileExists (const FTPCIPtr cip, const char *const file)
 
int FTPFileModificationTime (const FTPCIPtr cip, const char *const file, time_t *const mdtm)
 
int FTPFileSize (const FTPCIPtr cip, const char *const file, longest_int *const size, const int type)
 
int FTPFileSizeAndModificationTime (const FTPCIPtr cip, const char *const file, longest_int *const size, const int type, time_t *const mdtm)
 
int FTPFileType (const FTPCIPtr cip, const char *const file, int *const ftype)
 
int FTPGetCWD (const FTPCIPtr cip, char *const newCwd, const size_t newCwdSize)
 
int FTPGetFiles3 (const FTPCIPtr cip, const char *pattern, const char *const dstdir, const int recurse, int doGlob, const int xtype, const int resumeflag, int appendflag, const int deleteflag, const int tarflag, const ConfirmResumeDownloadProc resumeProc, int reserved)
 
int FTPGetOneFile3 (const FTPCIPtr cip, const char *const file, const char *const dstfile, const int xtype, const int fdtouse, const int resumeflag, const int appendflag, const int deleteflag, const ConfirmResumeDownloadProc resumeProc, int reserved)
 
int FTPInitConnectionInfo (const FTPLIPtr lip, const FTPCIPtr cip, size_t bufsize)
 
int FTPInitLibrary (const FTPLIPtr lip)
 
int FTPIsDir (const FTPCIPtr cip, const char *const dir)
 
int FTPIsRegularFile (const FTPCIPtr cip, const char *const file)
 
int FTPList (const FTPCIPtr cip, const int outfd, const int longMode, const char *const lsflag)
 
int FTPListToMemory (const FTPCIPtr cip, const char *const pattern, const LineListPtr llines, const char *const lsflags)
 
int FTPLocalGlob (FTPCIPtr cip, LineListPtr fileList, const char *pattern, int doGlob)
 
int FTPLoginHost (const FTPCIPtr cip)
 
int FTPMkdir (const FTPCIPtr cip, const char *const newDir, const int recurse)
 
int FTPMkdir2 (const FTPCIPtr cip, const char *const newDir, const int recurse, const char *const curDir)
 
int FTPOpenHost (const FTPCIPtr cip)
 
int FTPOpenHostNoLogin (const FTPCIPtr cip)
 
void FTPPerror (const FTPCIPtr cip, const int err, const int eerr, const char *const s1, const char *const s2)
 
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 ConfirmResumeUploadProc resumeProc, int reserved)
 
int FTPPutFiles3 (const FTPCIPtr cip, const char *const pattern, const char *const dstdir, 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 ConfirmResumeUploadProc resumeProc, int reserved)
 
int FTPRemoteGlob (FTPCIPtr cip, LineListPtr fileList, const char *pattern, int doGlob)
 
int FTPRename (const FTPCIPtr cip, const char *const oldname, const char *const newname)
 
int FTPRmdir (const FTPCIPtr cip, const char *const pattern, const int recurse, const int doGlob)
 
void FTPShutdownHost (const FTPCIPtr cip)
 
const charFTPStrError (int e)
 
int FTPSymlink (const FTPCIPtr cip, const char *const lfrom, const char *const lto)
 
int FTPUmask (const FTPCIPtr cip, const char *const umsk)
 
int FTPUtime (const FTPCIPtr cip, const char *const file, time_t actime, time_t modtime, time_t crtime)
 
int CopyLineList (LineListPtr, LineListPtr)
 
void DisposeLineListContents (LineListPtr)
 
void InitLineList (LineListPtr)
 
LinePtr RemoveLine (LineListPtr, LinePtr)
 
LinePtr AddLine (LineListPtr, const char *)
 
charStrDup (const char *)
 
charFGets (char *, size_t, FILE *)
 
void GetHomeDir (char *, size_t)
 
void GetUsrName (char *, size_t)
 
void Scramble (unsigned char *dst, size_t dsize, unsigned char *src, char *key)
 
time_t UnMDTMDate (char *)
 
int MkDirs (const char *const, int mode1)
 
charGetPass (const char *const prompt)
 
int FilenameExtensionIndicatesASCII (const char *const pathName, const char *const extnList)
 
void StrRemoveTrailingSlashes (char *dst)
 
int FTPGetOneFile (const FTPCIPtr cip, const char *const file, const char *const dstfile)
 
int FTPGetOneFile2 (const FTPCIPtr cip, const char *const file, const char *const dstfile, const int xtype, const int fdtouse, const int resumeflag, const int appendflag)
 
int FTPGetFiles (const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob)
 
int FTPGetFiles2 (const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob, const int xtype, const int resumeflag, const int appendflag)
 
int FTPGetOneFileAscii (const FTPCIPtr cip, const char *const file, const char *const dstfile)
 
int FTPGetFilesAscii (const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob)
 
int FTPPutOneFile (const FTPCIPtr cip, const char *const file, const char *const dstfile)
 
int FTPPutOneFile2 (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)
 
int FTPPutFiles (const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob)
 
int FTPPutFiles2 (const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob, const int xtype, const int appendflag, const char *const tmppfx, const char *const tmpsfx)
 
int FTPPutOneFileAscii (const FTPCIPtr cip, const char *const file, const char *const dstfile)
 
int FTPPutFilesAscii (const FTPCIPtr cip, const char *const pattern, const char *const dstdir, const int recurse, const int doGlob)
 
charFTPGetLocalCWD (char *buf, size_t size)
 
int FTPQueryFeatures (const FTPCIPtr)
 
int FTPMListOneFile (const FTPCIPtr cip, const char *const file, const MLstItemPtr mlip)
 
void FTPInitializeOurHostName (const FTPLIPtr)
 
void FTPInitializeAnonPassword (const FTPLIPtr)
 
int FTPListToMemory2 (const FTPCIPtr cip, const char *const pattern, const LineListPtr llines, const char *const lsflags, const int blanklines, int *const tryMLSD)
 
void FTPInitIOTimer (const FTPCIPtr)
 
int FTPStartDataCmd (const FTPCIPtr, int, int, longest_int, const char *,...)
 
void FTPStartIOTimer (const FTPCIPtr)
 
void FTPStopIOTimer (const FTPCIPtr)
 
void FTPUpdateIOTimer (const FTPCIPtr)
 
int FTPSetTransferType (const FTPCIPtr, int)
 
int FTPEndDataCmd (const FTPCIPtr, int)
 
int FTPRemoteHelp (const FTPCIPtr, const char *const, const LineListPtr)
 
int FTPCmdNoResponse (const FTPCIPtr, const char *const cmdspec,...)
 
int WaitResponse (const FTPCIPtr, unsigned int)
 
int FTPLocalRecursiveFileList (FTPCIPtr, LineListPtr, FileInfoListPtr)
 
int FTPLocalRecursiveFileList2 (FTPCIPtr cip, LineListPtr fileList, FileInfoListPtr files, int erelative)
 
int FTPRemoteRecursiveFileList (FTPCIPtr, LineListPtr, FileInfoListPtr)
 
int FTPRemoteRecursiveFileList1 (FTPCIPtr, char *const, FileInfoListPtr)
 
int FTPRebuildConnectionInfo (const FTPLIPtr lip, const FTPCIPtr cip)
 
int FTPFileExistsStat (const FTPCIPtr cip, const char *const file)
 
int FTPFileExistsNlst (const FTPCIPtr cip, const char *const file)
 
int FTPFileExists2 (const FTPCIPtr cip, const char *const file, const int tryMDTM, const int trySIZE, const int tryMLST, const int trySTAT, const int tryNLST)
 
int FTPFtw (const FTPCIPtr cip, const char *const dir, FTPFtwProc proc, int maxdepth)
 
int BufferGets (char *, size_t, int, char *, char **, char **, size_t)
 
void DisposeFileInfoListContents (FileInfoListPtr)
 
void InitFileInfoList (FileInfoListPtr)
 
void InitFileInfo (FileInfoPtr)
 
FileInfoPtr RemoveFileInfo (FileInfoListPtr, FileInfoPtr)
 
FileInfoPtr AddFileInfo (FileInfoListPtr, FileInfoPtr)
 
void SortFileInfoList (FileInfoListPtr, int, int)
 
void VectorizeFileInfoList (FileInfoListPtr)
 
void UnvectorizeFileInfoList (FileInfoListPtr)
 
int ComputeRNames (FileInfoListPtr, const char *, int, int)
 
int ComputeLNames (FileInfoListPtr, const char *, const char *, int)
 
int ConcatFileInfoList (FileInfoListPtr, FileInfoListPtr)
 
int ConcatFileToFileInfoList (FileInfoListPtr, char *)
 
int LineListToFileInfoList (LineListPtr, FileInfoListPtr)
 
int LineToFileInfoList (LinePtr, FileInfoListPtr)
 
void URLCopyToken (char *, size_t, const char *, size_t)
 
int UnMlsT (const char *const, const MLstItemPtr)
 
int UnMlsD (FileInfoListPtr, LineListPtr)
 
int UnLslR (FileInfoListPtr, LineListPtr, int)
 
void TraceResponse (const FTPCIPtr, ResponsePtr)
 
void PrintResponse (const FTPCIPtr, LineListPtr)
 
void DoneWithResponse (const FTPCIPtr, ResponsePtr)
 
ResponsePtr InitResponse (void)
 
void ReInitResponse (const FTPCIPtr, ResponsePtr)
 
int GetTelnetString (const FTPCIPtr, char *, size_t, FILE *, FILE *)
 
int GetResponse (const FTPCIPtr, ResponsePtr)
 
int RCmd (const FTPCIPtr, ResponsePtr, const char *,...)
 

Variables

char gLibNcFTPVersion [64]
 
int gLibNcFTP_Uses_Me_To_Quiet_Variable_Unused_Warnings
 

Macro Definition Documentation

◆ _SReadlineInfo_

#define _SReadlineInfo_   1

Definition at line 99 of file ncftp.h.

◆ closesocket

#define closesocket   close

Definition at line 477 of file ncftp.h.

◆ forever

#define forever   for ( ; ; )

Definition at line 73 of file ncftp.h.

◆ GLOBCHARSINSTR

#define GLOBCHARSINSTR (   a)    (strpbrk(a, kGlobChars) != NULL)

Definition at line 358 of file ncftp.h.

◆ INADDR_NONE

#define INADDR_NONE   (0xffffffff) /* <netinet/in.h> should have it. */

Definition at line 350 of file ncftp.h.

◆ ioctlsocket

#define ioctlsocket   ioctl

Definition at line 481 of file ncftp.h.

◆ IsLocalPathDelim

#define IsLocalPathDelim (   c)    (c == LOCAL_PATH_DELIM)

Definition at line 497 of file ncftp.h.

◆ kAcceptForReading

#define kAcceptForReading   00101

Definition at line 301 of file ncftp.h.

◆ kAcceptForWriting

#define kAcceptForWriting   00100

Definition at line 300 of file ncftp.h.

◆ kAppendNo

#define kAppendNo   0

Definition at line 365 of file ncftp.h.

◆ kAppendYes

#define kAppendYes   1

Definition at line 364 of file ncftp.h.

◆ kChdirAndGetCWD

#define kChdirAndGetCWD   00002

Definition at line 419 of file ncftp.h.

◆ kChdirAndMkdir

#define kChdirAndMkdir   00001

Definition at line 418 of file ncftp.h.

◆ kChdirOneSubdirAtATime

#define kChdirOneSubdirAtATime   00004

Definition at line 420 of file ncftp.h.

◆ kChdirOnly

#define kChdirOnly   00000

Definition at line 417 of file ncftp.h.

◆ kCommandAvailabilityUnknown

#define kCommandAvailabilityUnknown   (-1)

Definition at line 379 of file ncftp.h.

◆ kCommandAvailable

#define kCommandAvailable   1

Definition at line 380 of file ncftp.h.

◆ kCommandNotAvailable

#define kCommandNotAvailable   0

Definition at line 381 of file ncftp.h.

◆ kConfirmResumeProcNotUsed

#define kConfirmResumeProcNotUsed   0

Definition at line 423 of file ncftp.h.

◆ kConfirmResumeProcSaidAppend

#define kConfirmResumeProcSaidAppend   4

Definition at line 427 of file ncftp.h.

◆ kConfirmResumeProcSaidBestGuess

#define kConfirmResumeProcSaidBestGuess   5

Definition at line 428 of file ncftp.h.

◆ kConfirmResumeProcSaidCancel

#define kConfirmResumeProcSaidCancel   6

Definition at line 429 of file ncftp.h.

◆ kConfirmResumeProcSaidOverwrite

#define kConfirmResumeProcSaidOverwrite   3

Definition at line 426 of file ncftp.h.

◆ kConfirmResumeProcSaidResume

#define kConfirmResumeProcSaidResume   2

Definition at line 425 of file ncftp.h.

◆ kConfirmResumeProcSaidSkip

#define kConfirmResumeProcSaidSkip   1

Definition at line 424 of file ncftp.h.

◆ kDefaultAbortTimeout

#define kDefaultAbortTimeout   10

Definition at line 323 of file ncftp.h.

◆ kDefaultConnTimeout

#define kDefaultConnTimeout   30

Definition at line 321 of file ncftp.h.

◆ kDefaultCtrlTimeout

#define kDefaultCtrlTimeout   135

Definition at line 322 of file ncftp.h.

◆ kDefaultDataPortMode

#define kDefaultDataPortMode   kSendPortMode

Definition at line 344 of file ncftp.h.

◆ kDefaultFTPBufSize

#define kDefaultFTPBufSize   32768

Definition at line 314 of file ncftp.h.

◆ kDefaultFTPPort

#define kDefaultFTPPort   21

Definition at line 312 of file ncftp.h.

◆ kDefaultMaxDials

#define kDefaultMaxDials   3

Definition at line 341 of file ncftp.h.

◆ kDefaultRedialDelay

#define kDefaultRedialDelay   20 /* seconds */

Definition at line 342 of file ncftp.h.

◆ kDefaultXferTimeout

#define kDefaultXferTimeout   600

Definition at line 320 of file ncftp.h.

◆ kDeleteNo

#define kDeleteNo   0

Definition at line 369 of file ncftp.h.

◆ kDeleteYes

#define kDeleteYes   1

Definition at line 368 of file ncftp.h.

◆ kFallBackToSendPortMode

#define kFallBackToSendPortMode   2

Definition at line 297 of file ncftp.h.

◆ kFirewallFwuAtSiteFwpUserPass

#define kFirewallFwuAtSiteFwpUserPass   6

Definition at line 394 of file ncftp.h.

◆ kFirewallLastType

#define kFirewallLastType   kFirewallUserAtSiteFwuPassFwp

Definition at line 396 of file ncftp.h.

◆ kFirewallLoginThenUserAtSite

#define kFirewallLoginThenUserAtSite   2

Definition at line 390 of file ncftp.h.

◆ kFirewallNotInUse

#define kFirewallNotInUse   0

Definition at line 388 of file ncftp.h.

◆ kFirewallOpenSite

#define kFirewallOpenSite   4

Definition at line 392 of file ncftp.h.

◆ kFirewallSiteSite

#define kFirewallSiteSite   3

Definition at line 391 of file ncftp.h.

◆ kFirewallUserAtSite

#define kFirewallUserAtSite   1

Definition at line 389 of file ncftp.h.

◆ kFirewallUserAtSiteFwuPassFwp

#define kFirewallUserAtSiteFwuPassFwp   7

Definition at line 395 of file ncftp.h.

◆ kFirewallUserAtUserPassAtPass

#define kFirewallUserAtUserPassAtPass   5

Definition at line 393 of file ncftp.h.

◆ kFtwDir

#define kFtwDir   1

Definition at line 414 of file ncftp.h.

◆ kFtwFile

#define kFtwFile   0

Definition at line 413 of file ncftp.h.

◆ kGlobChars

#define kGlobChars   "[*?"

Definition at line 357 of file ncftp.h.

◆ kGlobNo

#define kGlobNo   0

Definition at line 361 of file ncftp.h.

◆ kGlobYes

#define kGlobYes   1

Definition at line 360 of file ncftp.h.

◆ kLibraryMagic

#define kLibraryMagic   "LibNcFTP 3.0.6"

Definition at line 65 of file ncftp.h.

◆ kLibraryVersion

#define kLibraryVersion   "@(#) LibNcFTP 3.0.6 (April 14, 2001)"

Definition at line 11 of file ncftp.h.

◆ kMalformedURL

#define kMalformedURL   (-2)

Definition at line 385 of file ncftp.h.

◆ kMlsOptModify

#define kMlsOptModify   00004

Definition at line 403 of file ncftp.h.

◆ kMlsOptPerm

#define kMlsOptPerm   00100

Definition at line 407 of file ncftp.h.

◆ kMlsOptSize

#define kMlsOptSize   00002

Definition at line 402 of file ncftp.h.

◆ kMlsOptType

#define kMlsOptType   00001

Definition at line 401 of file ncftp.h.

◆ kMlsOptUnique

#define kMlsOptUnique   01000

Definition at line 410 of file ncftp.h.

◆ kMlsOptUNIXgid

#define kMlsOptUNIXgid   00400

Definition at line 409 of file ncftp.h.

◆ kMlsOptUNIXgroup

#define kMlsOptUNIXgroup   00040

Definition at line 406 of file ncftp.h.

◆ kMlsOptUNIXmode

#define kMlsOptUNIXmode   00010

Definition at line 404 of file ncftp.h.

◆ kMlsOptUNIXowner

#define kMlsOptUNIXowner   00020

Definition at line 405 of file ncftp.h.

◆ kMlsOptUNIXuid

#define kMlsOptUNIXuid   00200

Definition at line 408 of file ncftp.h.

◆ kModTimeUnknown

#define kModTimeUnknown   ((time_t) (-1))

Definition at line 377 of file ncftp.h.

◆ kNetReading

#define kNetReading   kAcceptForReading

Definition at line 303 of file ncftp.h.

◆ kNetWriting

#define kNetWriting   kAcceptForWriting

Definition at line 302 of file ncftp.h.

◆ kNotURL

#define kNotURL   (-1)

Definition at line 384 of file ncftp.h.

◆ kPassiveMode

#define kPassiveMode   1

Definition at line 296 of file ncftp.h.

◆ kPreferredMlsOpts

◆ kPrEndMsg

#define kPrEndMsg   3

Definition at line 292 of file ncftp.h.

◆ kPrInitMsg

#define kPrInitMsg   1

Definition at line 290 of file ncftp.h.

◆ kPrUpdateMsg

#define kPrUpdateMsg   2

Definition at line 291 of file ncftp.h.

◆ kRecursiveNo

#define kRecursiveNo   0

Definition at line 363 of file ncftp.h.

◆ kRecursiveYes

#define kRecursiveYes   1

Definition at line 362 of file ncftp.h.

◆ kRedialStatusDialing

#define kRedialStatusDialing   0

Definition at line 346 of file ncftp.h.

◆ kRedialStatusSleeping

#define kRedialStatusSleeping   1

Definition at line 347 of file ncftp.h.

◆ kResponseNoPrint

#define kResponseNoPrint   00001

Definition at line 308 of file ncftp.h.

◆ kResponseNoProc

#define kResponseNoProc   00002

Definition at line 310 of file ncftp.h.

◆ kResponseNoSave

#define kResponseNoSave   00002

Definition at line 309 of file ncftp.h.

◆ kResumeNo

#define kResumeNo   0

Definition at line 367 of file ncftp.h.

◆ kResumeYes

#define kResumeYes   1

Definition at line 366 of file ncftp.h.

◆ kSendPortMode

#define kSendPortMode   0

Definition at line 295 of file ncftp.h.

◆ kServerTypeFTP_Max

#define kServerTypeFTP_Max   9

Definition at line 470 of file ncftp.h.

◆ kServerTypeMicrosoftFTP

#define kServerTypeMicrosoftFTP   4

Definition at line 465 of file ncftp.h.

◆ kServerTypeNcFTPd

#define kServerTypeNcFTPd   2

Definition at line 463 of file ncftp.h.

◆ kServerTypeNetWareFTP

#define kServerTypeNetWareFTP   11

Definition at line 472 of file ncftp.h.

◆ kServerTypeProFTPD

#define kServerTypeProFTPD   3

Definition at line 464 of file ncftp.h.

◆ kServerTypeRoxen

#define kServerTypeRoxen   10

Definition at line 471 of file ncftp.h.

◆ kServerTypeServ_U

#define kServerTypeServ_U   6

Definition at line 467 of file ncftp.h.

◆ kServerTypeUnknown

#define kServerTypeUnknown   0

Definition at line 461 of file ncftp.h.

◆ kServerTypeVFTPD

#define kServerTypeVFTPD   8

Definition at line 469 of file ncftp.h.

◆ kServerTypeWarFTPd

#define kServerTypeWarFTPd   5

Definition at line 466 of file ncftp.h.

◆ kServerTypeWFTPD

#define kServerTypeWFTPD   7

Definition at line 468 of file ncftp.h.

◆ kServerTypeWS_FTP

#define kServerTypeWS_FTP   12

Definition at line 473 of file ncftp.h.

◆ kServerTypeWuFTPd

#define kServerTypeWuFTPd   1

Definition at line 462 of file ncftp.h.

◆ kSizeUnknown

#define kSizeUnknown   ((longest_int) (-1))

Definition at line 376 of file ncftp.h.

◆ kSuggestedAbortTimeout

#define kSuggestedAbortTimeout   10

Definition at line 339 of file ncftp.h.

◆ kSuggestedDefaultConnTimeout

#define kSuggestedDefaultConnTimeout   30

Definition at line 337 of file ncftp.h.

◆ kSuggestedDefaultCtrlTimeout

#define kSuggestedDefaultCtrlTimeout   135 /* 2*MSL, + slop */

Definition at line 338 of file ncftp.h.

◆ kSuggestedDefaultXferTimeout

#define kSuggestedDefaultXferTimeout   (0) /* No timeout on data blocks. */

Definition at line 336 of file ncftp.h.

◆ kTarNo

#define kTarNo   0

Definition at line 371 of file ncftp.h.

◆ kTarYes

#define kTarYes   1

Definition at line 370 of file ncftp.h.

◆ kTypeAscii

#define kTypeAscii   'A'

Definition at line 353 of file ncftp.h.

◆ kTypeBinary

#define kTypeBinary   'I'

Definition at line 354 of file ncftp.h.

◆ kTypeEbcdic

#define kTypeEbcdic   'E'

Definition at line 355 of file ncftp.h.

◆ LIBNCFTP_USE_VAR

#define LIBNCFTP_USE_VAR (   a)    gLibNcFTP_Uses_Me_To_Quiet_Variable_Unused_Warnings = (a == 0)

Definition at line 521 of file ncftp.h.

◆ LOCAL_PATH_DELIM

#define LOCAL_PATH_DELIM   '/'

Definition at line 492 of file ncftp.h.

◆ LOCAL_PATH_DELIM_STR

#define LOCAL_PATH_DELIM_STR   "/"

Definition at line 493 of file ncftp.h.

◆ LocalPathToTVFSPath

#define LocalPathToTVFSPath (   s)

Definition at line 499 of file ncftp.h.

◆ longest_int

#define longest_int   long long

Definition at line 68 of file ncftp.h.

◆ longest_uint

#define longest_uint   unsigned long long

Definition at line 69 of file ncftp.h.

◆ NcSignal

#define NcSignal   signal

Definition at line 604 of file ncftp.h.

◆ NO_SIGNALS

#define NO_SIGNALS   1

Definition at line 49 of file ncftp.h.

◆ NoConfirmResumeDownloadProc

#define NoConfirmResumeDownloadProc   ((ConfirmResumeDownloadProc) 0)

Definition at line 451 of file ncftp.h.

◆ NoConfirmResumeUploadProc

#define NoConfirmResumeUploadProc   ((ConfirmResumeUploadProc) 0)

Definition at line 452 of file ncftp.h.

◆ NoGetPassphraseProc

#define NoGetPassphraseProc   ((FTPGetPassphraseProc) 0)

Definition at line 453 of file ncftp.h.

◆ StrFindLocalPathDelim

#define StrFindLocalPathDelim (   a)    strchr(a, LOCAL_PATH_DELIM)

Definition at line 494 of file ncftp.h.

◆ StrRemoveTrailingLocalPathDelim

#define StrRemoveTrailingLocalPathDelim   StrRemoveTrailingSlashes

Definition at line 496 of file ncftp.h.

◆ StrRFindLocalPathDelim

#define StrRFindLocalPathDelim (   a)    strrchr(a, LOCAL_PATH_DELIM)

Definition at line 495 of file ncftp.h.

◆ TVFSPathToLocalPath

#define TVFSPathToLocalPath (   s)

Definition at line 498 of file ncftp.h.

◆ UNIMPLEMENTED_CMD

#define UNIMPLEMENTED_CMD (   a)    ((a == 500) || (a == 502) || (a == 504))

Definition at line 373 of file ncftp.h.

◆ UNUSED

#define UNUSED (   a)    a

Definition at line 523 of file ncftp.h.

◆ USE_SIO

#define USE_SIO   1

Definition at line 46 of file ncftp.h.

Typedef Documentation

◆ ConfirmResumeDownloadProc

typedef int(* ConfirmResumeDownloadProc) (const char *volatile *localpath, volatile longest_int localsize, volatile time_t localmtime, const char *volatile remotepath, volatile longest_int remotesize, volatile time_t remotetime, volatile longest_int *volatile startPoint)

Definition at line 431 of file ncftp.h.

◆ ConfirmResumeUploadProc

typedef int(* ConfirmResumeUploadProc) (const char *volatile localpath, volatile longest_int localsize, volatile time_t localmtime, const char *volatile *remotepath, volatile longest_int remotesize, volatile time_t remotetime, volatile longest_int *volatile startPoint)

Definition at line 441 of file ncftp.h.

◆ FileInfo

◆ FileInfoList

◆ FileInfoListPtr

◆ FileInfoPtr

Definition at line 250 of file ncftp.h.

◆ FileInfoVec

Definition at line 250 of file ncftp.h.

◆ FTPCIPtr

Definition at line 124 of file ncftp.h.

◆ FTPConnectionInfo

◆ FTPConnectMessageProc

typedef void(* FTPConnectMessageProc) (const FTPCIPtr, ResponsePtr)

Definition at line 127 of file ncftp.h.

◆ FTPFtwProc

typedef int(* FTPFtwProc) (const FTPCIPtr cip, const char *fn, int flag)

Definition at line 131 of file ncftp.h.

◆ FTPGetPassphraseProc

typedef void(* FTPGetPassphraseProc) (const FTPCIPtr, LineListPtr pwPrompt, char *pass, size_t dsize)

Definition at line 132 of file ncftp.h.

◆ FTPLibraryInfo

◆ FTPLIPtr

◆ FTPLoginMessageProc

typedef void(* FTPLoginMessageProc) (const FTPCIPtr, ResponsePtr)

Definition at line 128 of file ncftp.h.

◆ FTPLogProc

typedef void(* FTPLogProc) (const FTPCIPtr, char *)

Definition at line 126 of file ncftp.h.

◆ FTPPrintResponseProc

typedef void(* FTPPrintResponseProc) (const FTPCIPtr, ResponsePtr)

Definition at line 130 of file ncftp.h.

◆ FTPProgressMeterProc

typedef void(* FTPProgressMeterProc) (const FTPCIPtr, int)

Definition at line 125 of file ncftp.h.

◆ FTPRedialStatusProc

typedef void(* FTPRedialStatusProc) (const FTPCIPtr, int, int)

Definition at line 129 of file ncftp.h.

◆ FTPSigProc

typedef void(* FTPSigProc) (int)

Definition at line 76 of file ncftp.h.

◆ Line

Definition at line 4085 of file wdfdevice.h.

◆ LineList

◆ LineListPtr

◆ LinePtr

typedef struct Line* LinePtr

Definition at line 78 of file ncftp.h.

◆ MLstItem

◆ MLstItemPtr

◆ Response

◆ ResponsePtr

◆ SReadlineInfo

Function Documentation

◆ AddFileInfo()

FileInfoPtr AddFileInfo ( FileInfoListPtr  list,
FileInfoPtr  src 
)

Definition at line 530 of file linelist.c.

531{
532 FileInfoPtr lp;
533
534 lp = (FileInfoPtr) malloc(sizeof(FileInfo));
535 if (lp != NULL) {
536 (void) memcpy(lp, src, sizeof(FileInfo));
537 lp->next = NULL;
538 if (list->first == NULL) {
539 list->first = list->last = lp;
540 lp->prev = NULL;
541 list->nFileInfos = 1;
542 } else {
543 lp->prev = list->last;
544 list->last->next = lp;
545 list->last = lp;
546 list->nFileInfos++;
547 }
548 }
549 return lp;
550} /* AddFileInfo */
Definition: list.h:37
struct list * next
Definition: list.h:38
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
GLenum src
Definition: glext.h:6340
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
struct FileInfo * FileInfoPtr
Definition: ncftp.h:250
FileInfoPtr prev
Definition: ncftp.h:252
FileInfoPtr next
Definition: ncftp.h:252

Referenced by ConcatFileInfoList(), ConcatFileToFileInfoList(), FTPLocalRecursiveFileList2(), Traverse(), UnLslR(), and UnMlsD().

◆ AddLine()

LinePtr AddLine ( LineListPtr  list,
const char buf1 
)

Definition at line 94 of file linelist.c.

95{
96 LinePtr lp;
97 char *buf;
98
99 lp = (LinePtr) malloc(sizeof(Line));
100 if (lp != NULL) {
101 buf = StrDup(buf1);
102 if (buf == NULL) {
103 free(lp);
104 lp = NULL;
105 } else {
106 lp->line = buf;
107 lp->next = NULL;
108 if (list->first == NULL) {
109 list->first = list->last = lp;
110 lp->prev = NULL;
111 list->nLines = 1;
112 } else {
113 lp->prev = list->last;
114 list->last->next = lp;
115 list->last = lp;
116 list->nLines++;
117 }
118 }
119 }
120 return lp;
121} /* AddLine */
#define free
Definition: debug_ros.c:5
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
struct Line * LinePtr
Definition: ncftp.h:78
#define StrDup
Definition: shlwapi.h:1533
Definition: ncftp.h:79
LinePtr prev
Definition: ncftp.h:80
char * line
Definition: ncftp.h:81
LinePtr next
Definition: ncftp.h:80

Referenced by CopyLineList(), FTPDecodeURL(), FTPListToMemory2(), FTPLocalGlob(), FTPRemoteGlob(), GetResponse(), and LazyUnixLocalGlob().

◆ BufferGets()

int BufferGets ( char buf,
size_t  bufsize,
int  inStream,
char secondaryBuf,
char **  secBufPtr,
char **  secBufLimit,
size_t  secBufSize 
)

Definition at line 978 of file rcmd.c.

979{
980 int err;
981 char *src;
982 char *dst;
983 char *dstlim;
984 int len;
985 int nr;
986 int haveEof = 0;
987
988 err = 0;
989 dst = buf;
990 dstlim = dst + bufsize - 1; /* Leave room for NUL. */
991 src = (*secBufPtr);
992 for ( ; dst < dstlim; ) {
993 if (src >= (*secBufLimit)) {
994 /* Fill the buffer. */
995
996/* Don't need to poll it here. The routines that use BufferGets don't
997 * need any special processing during timeouts (i.e. progress reports),
998 * so go ahead and just let it block until there is data to read.
999 */
1000 nr = (int) read(inStream, secondaryBuf, secBufSize);
1001 if (nr == 0) {
1002 /* EOF. */
1003 haveEof = 1;
1004 goto done;
1005 } else if (nr < 0) {
1006 /* Error. */
1007 err = -1;
1008 goto done;
1009 }
1010 (*secBufPtr) = secondaryBuf;
1011 (*secBufLimit) = secondaryBuf + nr;
1012 src = (*secBufPtr);
1013 if (nr < (int) secBufSize)
1014 src[nr] = '\0';
1015 }
1016 if (*src == '\r') {
1017 ++src;
1018 } else {
1019 if (*src == '\n') {
1020 /* *dst++ = *src++; */ ++src;
1021 goto done;
1022 }
1023 *dst++ = *src++;
1024 }
1025 }
1026
1027done:
1028 (*secBufPtr) = src;
1029 *dst = '\0';
1030 len = (int) (dst - buf);
1031 if (err < 0)
1032 return (err);
1033 if ((len == 0) && (haveEof == 1))
1034 return (-1);
1035 return (len); /* May be zero, if a blank line. */
1036} /* BufferGets */
#define read
Definition: acwin.h:96
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLenum GLenum dst
Definition: glext.h:6340
GLenum GLuint GLsizei bufsize
Definition: glext.h:7473
GLenum GLsizei len
Definition: glext.h:6722
ULONG nr
Definition: thread.c:7
#define err(...)

Referenced by FTPList(), and FTPListToMemory2().

◆ ComputeLNames()

int ComputeLNames ( FileInfoListPtr  dst,
const char srcdir,
const char dstdir,
int  nochop 
)

Definition at line 663 of file linelist.c.

664{
665 FileInfoPtr lp, lp2;
666 char *buf;
667 char *cp;
668
669 if (srcdir != NULL) {
670 cp = strrchr(srcdir, '/');
671 if (cp == NULL)
672 cp = strrchr(srcdir, '\\');
673 if (cp != NULL)
674 srcdir = cp + 1;
675 }
676 if (dstdir == NULL)
677 dstdir = ".";
678
679 for (lp = dst->first; lp != NULL; lp = lp2) {
680 lp2 = lp->next;
681
682 buf = NULL;
683 if (nochop != 0) {
684 if ((dstdir[0] != '\0') && (strcmp(dstdir, "."))) {
685 if (Dynscat(&buf, dstdir, "/", 0) == NULL)
686 goto memerr;
687 }
688 if (lp->lname != NULL) {
689 if (Dynscat(&buf, lp->lname, "/", 0) == NULL)
690 goto memerr;
691 } else if (srcdir != NULL) {
692 if (Dynscat(&buf, srcdir, "/", 0) == NULL)
693 goto memerr;
694 }
695 if (Dynscat(&buf, lp->relname, 0) == NULL)
696 goto memerr;
697 } else {
698 if ((dstdir[0] != '\0') && (strcmp(dstdir, "."))) {
699 cp = strrchr(lp->relname, '/');
700 if (cp == NULL)
701 cp = strrchr(lp->relname, '\\');
702 if (cp == NULL) {
703 cp = lp->relname;
704 } else {
705 cp++;
706 }
707 if (Dynscat(&buf, dstdir, "/", cp, 0) == NULL)
708 goto memerr;
709 } else {
710 cp = strrchr(lp->relname, '/');
711 if (cp == NULL)
712 cp = strrchr(lp->relname, '\\');
713 if (cp == NULL) {
714 cp = lp->relname;
715 } else {
716 cp++;
717 }
718 if (Dynscat(&buf, cp, 0) == NULL)
719 goto memerr;
720 }
721 }
722 if (buf == NULL) {
723memerr:
724 return (-1);
725 }
726 if (lp->lname != NULL) {
727 free(lp->lname);
728 lp->lname = NULL;
729 }
730 lp->lname = buf;
732 }
733 return (0);
734} /* ComputeLNames */
char * Dynscat(char **dst,...)
Definition: Dynscat.c:9
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
POINT cp
Definition: magnifier.c:59
#define TVFSPathToLocalPath(s)
Definition: ncftp.h:498
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
char * lname
Definition: ncftp.h:256
char * relname
Definition: ncftp.h:253

Referenced by FTPGetFiles3(), and FTPPutFiles3().

◆ ComputeRNames()

int ComputeRNames ( FileInfoListPtr  dst,
const char dstdir,
int  pflag,
int  nochop 
)

Definition at line 579 of file linelist.c.

580{
581 FileInfoPtr lp, lp2;
582 char *buf;
583 char *cp;
584
585 if (dstdir == NULL)
586 dstdir = ".";
587
588 for (lp = dst->first; lp != NULL; lp = lp2) {
589 lp2 = lp->next;
590
591 buf = NULL;
592 if (nochop != 0) {
593 if ((dstdir[0] != '\0') && (strcmp(dstdir, "."))) {
594 if (Dynscat(&buf, dstdir, "/", lp->relname, 0) == NULL)
595 goto memerr;
596
597 if (pflag != 0) {
598 /* Init lname to parent dir name of remote dir */
599 cp = strrchr(dstdir, '/');
600 if (cp == NULL)
601 cp = strrchr(dstdir, '\\');
602 if (cp != NULL) {
603 if (Dynscat(&lp->lname, cp + 1, 0) == NULL)
604 goto memerr;
606 }
607 }
608 } else {
609 if (Dynscat(&buf, lp->relname, 0) == NULL)
610 goto memerr;
611 }
612 } else {
613 if ((dstdir[0] != '\0') && (strcmp(dstdir, "."))) {
614 cp = strrchr(lp->relname, '/');
615 if (cp == NULL)
616 cp = strrchr(lp->relname, '\\');
617 if (cp != NULL) {
618 cp++;
619 } else {
620 cp = lp->relname;
621 }
622 if (Dynscat(&buf, dstdir, "/", cp, 0) == NULL)
623 goto memerr;
624
625 if (pflag != 0) {
626 /* Init lname to parent dir name of remote dir */
627 cp = strrchr(dstdir, '/');
628 if (cp == NULL)
629 cp = strrchr(dstdir, '\\');
630 if (cp != NULL) {
631 if (Dynscat(&lp->lname, cp + 1, 0) == NULL)
632 goto memerr;
634 }
635 }
636 } else {
637 cp = strrchr(lp->relname, '/');
638 if (cp == NULL)
639 cp = strrchr(lp->relname, '\\');
640 if (cp != NULL) {
641 cp++;
642 } else {
643 cp = lp->relname;
644 }
645 if (Dynscat(&buf, cp, 0) == NULL)
646 goto memerr;
647 }
648 }
649 lp->rname = buf;
650 if (lp->rname == NULL) {
651memerr:
652 return (-1);
653 }
655 }
656 return (0);
657} /* ComputeRNames */
#define LocalPathToTVFSPath(s)
Definition: ncftp.h:499
char * rname
Definition: ncftp.h:254

Referenced by FTPGetFiles3(), FTPPutFiles3(), FTPRemoteRecursiveFileList(), and FTPRemoteRecursiveFileList1().

◆ ConcatFileInfoList()

int ConcatFileInfoList ( FileInfoListPtr  dst,
FileInfoListPtr  src 
)

Definition at line 556 of file linelist.c.

557{
558 FileInfoPtr lp, lp2;
559 FileInfo newfi;
560
561 for (lp = src->first; lp != NULL; lp = lp2) {
562 lp2 = lp->next;
563 newfi = *lp;
564 newfi.relname = StrDup(lp->relname);
565 newfi.lname = StrDup(lp->lname);
566 newfi.rname = StrDup(lp->rname);
567 newfi.rlinkto = StrDup(lp->rlinkto);
568 newfi.plug = StrDup(lp->plug);
569 if (AddFileInfo(dst, &newfi) == NULL)
570 return (-1);
571 }
572 return (0);
573} /* ConcatFileInfoList */
FileInfoPtr AddFileInfo(FileInfoListPtr list, FileInfoPtr src)
Definition: linelist.c:530
char * rlinkto
Definition: ncftp.h:255
char * plug
Definition: ncftp.h:257

Referenced by FTPRemoteRecursiveFileList(), and FTPRemoteRecursiveFileList1().

◆ ConcatFileToFileInfoList()

int ConcatFileToFileInfoList ( FileInfoListPtr  dst,
char rfile 
)

Definition at line 740 of file linelist.c.

741{
742 FileInfo newfi;
743
744 InitFileInfo(&newfi); /* Use defaults. */
745 newfi.relname = StrDup(rfile);
746 newfi.rname = NULL;
747 newfi.lname = NULL;
748
749 if (AddFileInfo(dst, &newfi) == NULL)
750 return (-1);
751 return (0);
752} /* ConcatFileToFileInfoList */
void InitFileInfo(FileInfoPtr fip)
Definition: linelist.c:471

Referenced by FTPRemoteRecursiveFileList(), FTPRemoteRecursiveFileList1(), LineListToFileInfoList(), and LineToFileInfoList().

◆ CopyLineList()

int CopyLineList ( LineListPtr  dst,
LineListPtr  src 
)

Definition at line 127 of file linelist.c.

128{
129 LinePtr lp, lp2;
130
132 for (lp = src->first; lp != NULL; ) {
133 lp2 = lp;
134 lp = lp->next;
135 if (lp2->line != NULL) {
136 if (AddLine(dst, lp2->line) == NULL) {
138 return (-1);
139 }
140 }
141 }
142 return (0);
143} /* CopyLineList */
void InitLineList(LineListPtr list)
Definition: linelist.c:54
void DisposeLineListContents(LineListPtr list)
Definition: linelist.c:33
LinePtr AddLine(LineListPtr list, const char *buf1)
Definition: linelist.c:94

Referenced by FTPRemoteHelp().

◆ DisposeFileInfoListContents()

void DisposeFileInfoListContents ( FileInfoListPtr  list)

Definition at line 152 of file linelist.c.

153{
154 FileInfoPtr lp, lp2;
155
156 for (lp = list->first; lp != NULL; ) {
157 lp2 = lp;
158 lp = lp->next;
159 if (lp2->relname != NULL) {
160 lp2->relname[0] = '\0';
161 free(lp2->relname);
162 }
163 if (lp2->lname != NULL) {
164 lp2->lname[0] = '\0';
165 free(lp2->lname);
166 }
167 if (lp2->rname != NULL) {
168 lp2->rname[0] = '\0';
169 free(lp2->rname);
170 }
171 if (lp2->rlinkto != NULL) {
172 lp2->rlinkto[0] = '\0';
173 free(lp2->rlinkto);
174 }
175 if (lp2->plug != NULL) {
176 lp2->plug[0] = '\0';
177 free(lp2->plug);
178 }
179 free(lp2);
180 }
181
182 if (list->vec != NULL)
183 free(list->vec);
184
185 /* Same as InitFileInfoList. */
186 (void) memset(list, 0, sizeof(FileInfoList));
187} /* DisposeFileInfoListContents */
#define memset(x, y, z)
Definition: compat.h:39

Referenced by FlushLsCacheItem(), FTPGetFiles3(), FTPPutFiles3(), FTPRemoteRecursiveFileList(), and FTPRemoteRecursiveFileList1().

◆ DisposeLineListContents()

void DisposeLineListContents ( LineListPtr  list)

Definition at line 33 of file linelist.c.

34{
35 LinePtr lp, lp2;
36
37 for (lp = list->first; lp != NULL; ) {
38 lp2 = lp;
39 lp = lp->next;
40 if (lp2->line != NULL) {
41 lp2->line[0] = '\0';
42 free(lp2->line);
43 }
44 free(lp2);
45 }
46 /* Same as InitLineList. */
47 (void) memset(list, 0, sizeof(LineList));
48} /* DisposeLineListContents */
Definition: ncftp.h:84

Referenced by ChdirCmd(), CopyLineList(), DoneWithResponse(), EchoCmd(), FTPChmod(), FTPDeallocateHost(), FTPDelete(), FTPFileExistsNlst(), FTPFileExistsStat(), FTPFtwL2(), FTPGetFiles3(), FTPPutFiles3(), FTPRemoteRecursiveFileList(), FTPRemoteRecursiveFileList1(), FTPRmdir(), FTPRmdirRecursiveL2(), LocalRmCmd(), LocalRmdirCmd(), Ls(), OpenCmd(), ReInitResponse(), RGlobCmd(), RmtHelpCmd(), SaveLastResponse(), SpoolGetCmd(), and SpoolPutCmd().

◆ DoneWithResponse()

void DoneWithResponse ( const  FTPCIPtr,
ResponsePtr  rp 
)

Definition at line 114 of file rcmd.c.

115{
116 /* Dispose space taken up by the Response, and clear it out
117 * again. For some reason, I like to return memory to zeroed
118 * when not in use.
119 */
120 if (rp != NULL) {
121 TraceResponse(cip, rp);
122 if (cip->printResponseProc != 0) {
123 if ((rp->printMode & kResponseNoProc) == 0)
124 (*cip->printResponseProc)(cip, rp);
125 }
126 if ((rp->printMode & kResponseNoSave) == 0)
127 SaveLastResponse(cip, rp);
128 else
130 (void) memset(rp, 0, sizeof(Response));
131 free(rp);
132 }
133} /* DoneWithResponse */
#define kResponseNoProc
Definition: ncftp.h:310
#define kResponseNoSave
Definition: ncftp.h:309
static void SaveLastResponse(const FTPCIPtr cip, ResponsePtr rp)
Definition: rcmd.c:89
void TraceResponse(const FTPCIPtr cip, ResponsePtr rp)
Definition: rcmd.c:55
Definition: ncftp.h:89
int printMode
Definition: ncftp.h:93
LineList msg
Definition: ncftp.h:90

Referenced by FTPAbortDataTransfer(), FTPChdirAndGetCWD(), FTPCloseHost(), FTPCmd(), FTPEndDataCmd(), FTPFileExistsStat(), FTPFileModificationTime(), FTPFileSize(), FTPGetCWD(), FTPLoginHost(), FTPMListOneFile(), FTPQueryFeatures(), FTPRemoteHelp(), FTPStartDataCmd(), FTPUtime(), nFTPChdirAndGetCWD(), OpenControlConnection(), Passive(), SendPort(), and SetStartOffset().

◆ FGets()

char * FGets ( char str,
size_t  size,
FILE fp 
)

Definition at line 111 of file util.c.

112{
113 char *cp, *nlptr;
114
115 cp = fgets(str, ((int) size) - 1, fp);
116 if (cp != NULL) {
117 cp[((int) size) - 1] = '\0'; /* ensure terminator */
118 nlptr = cp + strlen(cp) - 1;
119 if (*nlptr == '\n')
120 *nlptr = '\0';
121 } else {
122 memset(str, 0, size);
123 }
124 return cp;
125} /* FGets */
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLsizeiptr size
Definition: glext.h:5919
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
const WCHAR * str

Referenced by GetBookmark(), GetNextBookmark(), LazyUnixLocalGlob(), OpenBookmarkFile(), PromptForBookmarkName(), PutBookmark(), and RunBookmarkEditor().

◆ FilenameExtensionIndicatesASCII()

int FilenameExtensionIndicatesASCII ( const char *const  pathName,
const char *const  extnList 
)

Definition at line 963 of file util.c.

964{
965 const char *extn;
966 char *cp;
967 int c;
968 char extnPattern[16];
969
970 extn = pathName + strlen(pathName) - 1;
971 forever {
972 if (extn <= pathName)
973 return (0); /* End of pathname, no extension. */
974 c = (int) *--extn;
975 if (IsLocalPathDelim(c))
976 return (0); /* End of filename, no extension. */
977 if (c == '.') {
978 extn += 1;
979 break;
980 }
981 }
982 if (strlen(extn) > (sizeof(extnPattern) - 2 - 1 - 1)) {
983 return (0);
984 }
985#ifdef HAVE_SNPRINTF
986 snprintf(extnPattern, sizeof(extnPattern),
987#else
988 sprintf(extnPattern,
989#endif
990 "|.%s|",
991 extn
992 );
993
994 cp = extnPattern;
995 forever {
996 c = *cp;
997 if (c == '\0')
998 break;
999 if (isupper(c)) {
1000 c = tolower(c);
1001 *cp++ = (char) c;
1002 } else {
1003 cp++;
1004 }
1005 }
1006
1007 /* Extension list is specially formatted, like this:
1008 *
1009 * |ext1|ext2|ext3|...|extN|
1010 *
1011 * I.e, each filename extension is delimited with
1012 * a pipe, and we always begin and end the string
1013 * with a pipe.
1014 */
1015 if (strstr(extnList, extnPattern) != NULL) {
1016 return (1);
1017 }
1018 return (0);
1019} /* FilenameExtensionIndicatesASCII */
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
#define isupper(c)
Definition: acclib.h:71
int tolower(int c)
Definition: utclib.c:902
unsigned char
Definition: typeof.h:29
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define forever
Definition: ncftp.h:73
#define IsLocalPathDelim(c)
Definition: ncftp.h:497
#define snprintf
Definition: wintirpc.h:48

Referenced by AutomaticallyUseASCIIModeDependingOnExtension().

◆ FTPAbortDataTransfer()

void FTPAbortDataTransfer ( const FTPCIPtr  cip)

Definition at line 870 of file rcmd.c.

871{
872 ResponsePtr rp;
873 int result;
874
875 if (cip->dataSocket != kClosedFileDescriptor) {
876 PrintF(cip, "Starting abort sequence.\n");
877 SendTelnetInterrupt(cip); /* Probably could get by w/o doing this. */
878
879 result = FTPCmdNoResponse(cip, "ABOR");
880 if (result != kNoErr) {
881 /* Linger could cause close to block, so unset it. */
882 (void) SetLinger(cip, cip->dataSocket, 0);
884 PrintF(cip, "Could not send abort command.\n");
885 return;
886 }
887
888 if (cip->abortTimeout > 0) {
889 result = WaitResponse(cip, (unsigned int) cip->abortTimeout);
890 if (result <= 0) {
891 /* Error or no response received to ABOR in time. */
892 (void) SetLinger(cip, cip->dataSocket, 0);
894 PrintF(cip, "No response received to abort request.\n");
895 return;
896 }
897 }
898
899 rp = InitResponse();
900 if (rp == NULL) {
901 Error(cip, kDontPerror, "Malloc failed.\n");
902 cip->errNo = kErrMallocFailed;
903 result = cip->errNo;
904 return;
905 }
906
907 result = GetResponse(cip, rp);
908 if (result < 0) {
909 /* Shouldn't happen, and doesn't matter if it does. */
910 (void) SetLinger(cip, cip->dataSocket, 0);
912 PrintF(cip, "Invalid response to abort request.\n");
913 DoneWithResponse(cip, rp);
914 return;
915 }
916 DoneWithResponse(cip, rp);
917
918 /* A response to the abort request has been received.
919 * Now the only thing left to do is close the data
920 * connection, making sure to turn off linger mode
921 * since we don't care about straggling data bits.
922 */
923 (void) SetLinger(cip, cip->dataSocket, 0);
924 CloseDataConnection(cip); /* Must close (by protocol). */
925 PrintF(cip, "End abort.\n");
926 }
927} /* FTPAbortDataTransfer */
BOOL Error
Definition: chkdsk.c:66
GLuint64EXT * result
Definition: glext.h:11304
void SendTelnetInterrupt(const FTPCIPtr cip)
Definition: ftp.c:1328
void CloseDataConnection(const FTPCIPtr cip)
Definition: ftp.c:831
int SetLinger(const FTPCIPtr cip, int sockfd, int onoff)
Definition: ftp.c:262
void PrintF(const FTPCIPtr cip, const char *const fmt,...)
Definition: util.c:340
#define kDontPerror
Definition: util.h:45
#define kClosedFileDescriptor
Definition: util.h:47
#define kNoErr
Definition: ncftp_errno.h:9
#define kErrMallocFailed
Definition: ncftp_errno.h:40
void DoneWithResponse(const FTPCIPtr cip, ResponsePtr rp)
Definition: rcmd.c:114
int FTPCmdNoResponse(const FTPCIPtr cip, const char *const cmdspec,...)
Definition: rcmd.c:656
int WaitResponse(const FTPCIPtr cip, unsigned int sec)
Definition: rcmd.c:684
int GetResponse(const FTPCIPtr cip, ResponsePtr rp)
Definition: rcmd.c:287
ResponsePtr InitResponse(void)
Definition: rcmd.c:38
unsigned int abortTimeout
Definition: ncftp.h:144

Referenced by FTPCloseHost(), FTPGetOneF(), and FTPPutOneF().

◆ FTPChdir()

int FTPChdir ( const FTPCIPtr  cip,
const char *const  cdCwd 
)

Definition at line 11 of file cmds.c.

12{
13 int result;
14
15 if (cip == NULL)
16 return (kErrBadParameter);
17 if (strcmp(cip->magic, kLibraryMagic))
18 return (kErrBadMagic);
19
20 if (cdCwd == NULL) {
23 } else {
24 if (cdCwd[0] == '\0') /* But allow FTPChdir(cip, ".") to go through. */
25 result = 2;
26 else if (strcmp(cdCwd, "..") == 0)
27 result = FTPCmd(cip, "CDUP");
28 else
29 result = FTPCmd(cip, "CWD %s", cdCwd);
30 if (result >= 0) {
31 if (result == 2) {
32 result = kNoErr;
33 } else {
35 cip->errNo = kErrCWDFailed;
36 }
37 }
38 }
39 return (result);
40} /* FTPChdir */
int FTPCmd(const FTPCIPtr cip, const char *const cmdspec,...)
Definition: rcmd.c:603
#define kLibraryMagic
Definition: ncftp.h:65
#define kErrInvalidDirParam
Definition: ncftp_errno.h:39
#define kErrBadMagic
Definition: ncftp_errno.h:55
#define kErrBadParameter
Definition: ncftp_errno.h:56
#define kErrCWDFailed
Definition: ncftp_errno.h:42
char magic[16]
Definition: ncftp.h:135

Referenced by FTPChdir3(), FTPFileExistsNlst(), FTPFileExistsStat(), FTPFileType(), FTPFtw(), FTPFtwL2(), FTPMkdir2(), FTPRemoteRecursiveFileList(), FTPRemoteRecursiveFileList1(), FTPRmdirRecursive(), FTPRmdirRecursiveL2(), OpenCmd(), and OpenURL().

◆ FTPChdir3()

int FTPChdir3 ( FTPCIPtr  cip,
const char *const  cdCwd,
char *const  newCwd,
const size_t  newCwdSize,
int  flags 
)

Definition at line 376 of file cmds.c.

377{
378 char *cp, *startcp;
379 int result;
380 int lastSubDir;
381 int mkd, pwd;
382
383 if (cip == NULL)
384 return (kErrBadParameter);
385 if (strcmp(cip->magic, kLibraryMagic))
386 return (kErrBadMagic);
387
388 if (cdCwd == NULL) {
391 return result;
392 }
393
394 if (flags == kChdirOnly)
395 return (FTPChdir(cip, cdCwd));
396 if (flags == kChdirAndGetCWD) {
397 return (FTPChdirAndGetCWD(cip, cdCwd, newCwd, newCwdSize));
398 } else if (flags == kChdirAndMkdir) {
399 result = FTPMkdir(cip, cdCwd, kRecursiveYes);
400 if (result == kNoErr)
401 result = FTPChdir(cip, cdCwd);
402 return result;
403 } else if (flags == (kChdirAndMkdir|kChdirAndGetCWD)) {
404 result = FTPMkdir(cip, cdCwd, kRecursiveYes);
405 if (result == kNoErr)
406 result = FTPChdirAndGetCWD(cip, cdCwd, newCwd, newCwdSize);
407 return result;
408 }
409
410 /* else: (flags | kChdirOneSubdirAtATime) == true */
411
412 cp = cip->buf;
413 cp[cip->bufSize - 1] = '\0';
414 (void) Strncpy(cip->buf, cdCwd, cip->bufSize);
415 if (cp[cip->bufSize - 1] != '\0')
416 return (kErrBadParameter);
417
418 mkd = (flags & kChdirAndMkdir);
420
421 if ((cdCwd[0] == '\0') || (strcmp(cdCwd, ".") == 0)) {
422 result = 0;
423 if (flags == kChdirAndGetCWD)
424 result = FTPGetCWD(cip, newCwd, newCwdSize);
425 return (result);
426 }
427
428 lastSubDir = 0;
429 do {
430 startcp = cp;
432 if (cp != NULL) {
433 /* If this is the first slash in an absolute
434 * path, then startcp will be empty. We will
435 * use this below to treat this as the root
436 * directory.
437 */
438 *cp++ = '\0';
439 } else {
440 lastSubDir = 1;
441 }
442 if (strcmp(startcp, ".") == 0) {
443 result = 0;
444 if ((lastSubDir != 0) && (pwd != 0))
445 result = FTPGetCWD(cip, newCwd, newCwdSize);
446 } else if ((lastSubDir != 0) && (pwd != 0)) {
447 result = FTPChdirAndGetCWD(cip, (*startcp != '\0') ? startcp : "/", newCwd, newCwdSize);
448 } else {
449 result = FTPChdir(cip, (*startcp != '\0') ? startcp : "/");
450 }
451 if (result < 0) {
452 if ((mkd != 0) && (*startcp != '\0')) {
453 if (FTPCmd(cip, "MKD %s", startcp) == 2) {
454 result = FTPChdir(cip, startcp);
455 } else {
456 /* couldn't change nor create */
457 cip->errNo = result;
458 }
459 } else {
460 cip->errNo = result;
461 }
462 }
463 } while ((!lastSubDir) && (result == 0));
464
465 return (result);
466} /* FTPChdir3 */
char * Strncpy(char *const, const char *const, const size_t)
Definition: Strncpy.c:11
void pwd(int argc, const char *argv[])
Definition: cmds.c:1401
GLbitfield flags
Definition: glext.h:7161
int FTPMkdir(const FTPCIPtr cip, const char *const newDir, const int recurse)
Definition: cmds.c:641
int FTPGetCWD(const FTPCIPtr cip, char *const newCwd, const size_t newCwdSize)
Definition: cmds.c:254
int FTPChdir(const FTPCIPtr cip, const char *const cdCwd)
Definition: cmds.c:11
int FTPChdirAndGetCWD(const FTPCIPtr cip, const char *const cdCwd, char *const newCwd, const size_t newCwdSize)
Definition: cmds.c:313
#define kChdirAndGetCWD
Definition: ncftp.h:419
#define StrFindLocalPathDelim(a)
Definition: ncftp.h:494
#define kChdirAndMkdir
Definition: ncftp.h:418
#define kRecursiveYes
Definition: ncftp.h:362
#define kChdirOnly
Definition: ncftp.h:417
size_t bufSize
Definition: ncftp.h:187
char * buf
Definition: ncftp.h:186

◆ FTPChdirAndGetCWD()

int FTPChdirAndGetCWD ( const FTPCIPtr  cip,
const char *const  cdCwd,
char *const  newCwd,
const size_t  newCwdSize 
)

Definition at line 313 of file cmds.c.

314{
315 ResponsePtr rp;
316 char *l, *r;
317 int result;
318
319 if (cip == NULL)
320 return (kErrBadParameter);
321 if (strcmp(cip->magic, kLibraryMagic))
322 return (kErrBadMagic);
323
324 if ((newCwd == NULL) || (cdCwd == NULL)) {
327 } else {
328 if (cdCwd[0] == '\0') { /* But allow FTPChdir(cip, ".") to go through. */
329 result = FTPGetCWD(cip, newCwd, newCwdSize);
330 return (result);
331 }
332 rp = InitResponse();
333 if (rp == NULL) {
335 cip->errNo = kErrMallocFailed;
336 Error(cip, kDontPerror, "Malloc failed.\n");
337 } else {
338 if (strcmp(cdCwd, "..") == 0)
339 result = RCmd(cip, rp, "CDUP");
340 else
341 result = RCmd(cip, rp, "CWD %s", cdCwd);
342 if (result == 2) {
343 l = strchr(rp->msg.first->line, '"');
344 if ((l == rp->msg.first->line) && ((r = strrchr(rp->msg.first->line, '"')) != NULL) && (l != r)) {
345 /* "xxxx" is current directory.
346 * Strip out just the xxxx to copy into the remote cwd.
347 *
348 * This is nice because we didn't have to do a PWD.
349 */
350 *r = '\0';
351 ++l;
352 (void) Strncpy(newCwd, l, newCwdSize);
353 *r = '"'; /* Restore, so response prints correctly. */
354 DoneWithResponse(cip, rp);
355 result = kNoErr;
356 } else {
357 DoneWithResponse(cip, rp);
358 result = FTPGetCWD(cip, newCwd, newCwdSize);
359 }
360 } else if (result > 0) {
362 cip->errNo = kErrCWDFailed;
363 DoneWithResponse(cip, rp);
364 } else {
365 DoneWithResponse(cip, rp);
366 }
367 }
368 }
369 return (result);
370} /* FTPChdirAndGetCWD */
char * strchr(const char *String, int ch)
Definition: utclib.c:501
r l[0]
Definition: byte_order.h:168
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
int RCmd(const FTPCIPtr, ResponsePtr, const char *,...)
Definition: rcmd.c:718
void DoneWithResponse(const FTPCIPtr, ResponsePtr)
Definition: rcmd.c:114
ResponsePtr InitResponse(void)
Definition: rcmd.c:38
LinePtr first
Definition: ncftp.h:85

Referenced by FTPChdir3().

◆ FTPChmod()

int FTPChmod ( const FTPCIPtr  cip,
const char *const  pattern,
const char *const  mode,
const int  doGlob 
)

Definition at line 46 of file cmds.c.

47{
48 LineList fileList;
49 LinePtr filePtr;
50 char *file;
51 int onceResult, batchResult;
52
53 if (cip == NULL)
54 return (kErrBadParameter);
55 if (strcmp(cip->magic, kLibraryMagic))
56 return (kErrBadMagic);
57
58 batchResult = FTPRemoteGlob(cip, &fileList, pattern, doGlob);
59 if (batchResult != kNoErr)
60 return (batchResult);
61
62 for (batchResult = kNoErr, filePtr = fileList.first;
63 filePtr != NULL;
64 filePtr = filePtr->next)
65 {
66 file = filePtr->line;
67 if (file == NULL) {
68 batchResult = kErrBadLineList;
70 break;
71 }
72 onceResult = FTPCmd(cip, "SITE CHMOD %s %s", mode, file);
73 if (onceResult < 0) {
74 batchResult = onceResult;
75 break;
76 }
77 if (onceResult != 2) {
78 batchResult = kErrChmodFailed;
80 }
81 }
82 DisposeLineListContents(&fileList);
83 return (batchResult);
84} /* FTPChmod */
GLubyte * pattern
Definition: glext.h:7787
GLenum mode
Definition: glext.h:6217
int FTPRemoteGlob(FTPCIPtr cip, LineListPtr fileList, const char *pattern, int doGlob)
Definition: glob.c:1341
#define kErrChmodFailed
Definition: ncftp_errno.h:59
#define kErrBadLineList
Definition: ncftp_errno.h:44
Definition: fci.c:127

Referenced by ChmodCmd().

◆ FTPCloseHost()

int FTPCloseHost ( const FTPCIPtr  cip)

Definition at line 523 of file open.c.

524{
525 ResponsePtr rp;
526 int result;
527
528 if (cip == NULL)
529 return (kErrBadParameter);
530 if (strcmp(cip->magic, kLibraryMagic))
531 return (kErrBadMagic);
532
533 /* Data connection shouldn't be open normally. */
536
537 result = kNoErr;
538 if (cip->connected != 0) {
539 rp = InitResponse();
540 if (rp == NULL) {
541 cip->errNo = kErrMallocFailed;
542 result = cip->errNo;
543 } else {
544 rp->eofOkay = 1; /* We are expecting EOF after this cmd. */
545 cip->eofOkay = 1;
546 (void) RCmd(cip, rp, "QUIT");
547 DoneWithResponse(cip, rp);
548 }
549 }
550
552
553 /* Dispose dynamic data structures, so you won't leak
554 * if you OpenHost with this again.
555 */
557 return (result);
558} /* FTPCloseHost */
void CloseControlConnection(const FTPCIPtr cip)
Definition: ftp.c:197
static void FTPDeallocateHost(const FTPCIPtr cip)
Definition: open.c:11
void FTPAbortDataTransfer(const FTPCIPtr cip)
Definition: rcmd.c:870
int eofOkay
Definition: ncftp.h:94

Referenced by CloseHost(), and FTPOpenHost().

◆ FTPCmd()

int FTPCmd ( const FTPCIPtr  cip,
const char *const  cmdspec,
  ... 
)

Definition at line 603 of file rcmd.c.

604{
605 va_list ap;
606 int result;
607 ResponsePtr rp;
608
609 if (cip == NULL)
610 return (kErrBadParameter);
611 if (strcmp(cip->magic, kLibraryMagic))
612 return (kErrBadMagic);
613
614 rp = InitResponse();
615 if (rp == NULL) {
617 cip->errNo = kErrMallocFailed;
618 Error(cip, kDontPerror, "Malloc failed.\n");
619 return (cip->errNo);
620 }
621
622 va_start(ap, cmdspec);
623#ifndef NO_SIGNALS
624 if (cip->ctrlTimeout > 0)
625 (void) alarm(cip->ctrlTimeout);
626#endif /* NO_SIGNALS */
627 result = SendCommand(cip, cmdspec, ap);
628 va_end(ap);
629 if (result < 0) {
630#ifndef NO_SIGNALS
631 if (cip->ctrlTimeout > 0)
632 (void) alarm(0);
633#endif /* NO_SIGNALS */
634 return (result);
635 }
636
637 /* Get the response to the command we sent. */
638 result = GetResponse(cip, rp);
639#ifndef NO_SIGNALS
640 if (cip->ctrlTimeout > 0)
641 (void) alarm(0);
642#endif /* NO_SIGNALS */
643
644 if (result == kNoErr)
645 result = rp->codeType;
646 DoneWithResponse(cip, rp);
647 return (result);
648} /* FTPCmd */
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
static int SendCommand(const FTPCIPtr cip, const char *cmdspec, va_list ap)
Definition: rcmd.c:496
unsigned int ctrlTimeout
Definition: ncftp.h:143
int codeType
Definition: ncftp.h:91
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36

Referenced by DoOpen(), FTPChdir(), FTPChdir3(), FTPChmod(), FTPDelete(), FTPGetOneF(), FTPMkdir2(), FTPPutOneF(), FTPRename(), FTPRequestMlsOptions(), FTPRmdir(), FTPSetTransferType(), FTPSymlink(), FTPUmask(), QuoteCmd(), and SiteCmd().

◆ FTPCmdNoResponse()

int FTPCmdNoResponse ( const  FTPCIPtr,
const char *const  cmdspec,
  ... 
)

Definition at line 656 of file rcmd.c.

657{
658 va_list ap;
659
660 if (cip == NULL)
661 return (kErrBadParameter);
662 if (strcmp(cip->magic, kLibraryMagic))
663 return (kErrBadMagic);
664
665 va_start(ap, cmdspec);
666#ifndef NO_SIGNALS
667 if (cip->ctrlTimeout > 0)
668 (void) alarm(cip->ctrlTimeout);
669#endif /* NO_SIGNALS */
670 (void) SendCommand(cip, cmdspec, ap);
671#ifndef NO_SIGNALS
672 if (cip->ctrlTimeout > 0)
673 (void) alarm(0);
674#endif /* NO_SIGNALS */
675 va_end(ap);
676
677 return (kNoErr);
678} /* FTPCmdNoResponse */

Referenced by FTPAbortDataTransfer().

◆ FTPDecodeURL()

int FTPDecodeURL ( const FTPCIPtr  cip,
char *const  url,
LineListPtr  cdlist,
char *const  fn,
const size_t  fnsize,
int *const  xtype,
int *const  wantnlst 
)

Definition at line 639 of file open.c.

648{
649 char *cp;
650 char *hstart, *hend;
651 char *h2start;
652 char *at1;
653 char portstr[32];
654 int port;
655 int sc;
656 char *lastslash;
657 char *parsestr;
658 char *tok;
659 char subdir[128];
660 char *semi;
661
662 InitLineList(cdlist);
663 *fn = '\0';
664 if (wantnlst != NULL)
665 *wantnlst = 0;
666 if (xtype != NULL)
667 *xtype = kTypeBinary;
668
669 cp = NULL; /* shut up warnings */
670#ifdef HAVE_STRCASECMP
671 if (strncasecmp(url, "<URL:ftp://", 11) == 0) {
672 cp = url + strlen(url) - 1;
673 if (*cp != '>')
674 return (kMalformedURL); /* missing closing > */
675 *cp = '\0';
676 cp = url + 11;
677 } else if (strncasecmp(url, "ftp://", 6) == 0) {
678 cp = url + 6;
679 } else {
680 return (-1); /* not a RFC 1738 URL */
681 }
682#else /* HAVE_STRCASECMP */
683 if (strncmp(url, "<URL:ftp://", 11) == 0) {
684 cp = url + strlen(url) - 1;
685 if (*cp != '>')
686 return (kMalformedURL); /* missing closing > */
687 *cp = '\0';
688 cp = url + 11;
689 } else if (strncmp(url, "ftp://", 6) == 0) {
690 cp = url + 6;
691 } else {
692 return (-1); /* not a RFC 1738 URL */
693 }
694#endif /* HAVE_STRCASECMP */
695
696 /* //<user>:<password>@<host>:<port>/<url-path> */
697
698 at1 = NULL;
699 for (hstart = cp; ; cp++) {
700 if (*cp == '@') {
701 if (at1 == NULL)
702 at1 = cp;
703 else
704 return (kMalformedURL);
705 } else if ((*cp == '\0') || (*cp == '/')) {
706 hend = cp;
707 break;
708 }
709 }
710
711 sc = *hend;
712 *hend = '\0';
713 if (at1 == NULL) {
714 /* no user or password */
715 h2start = hstart;
716 } else {
717 *at1 = '\0';
718 cp = strchr(hstart, ':');
719 if (cp == NULL) {
720 /* whole thing is the user name then */
721 URLCopyToken(cip->user, sizeof(cip->user), hstart, (size_t) (at1 - hstart));
722 } else if (strchr(cp + 1, ':') != NULL) {
723 /* Too many colons */
724 return (kMalformedURL);
725 } else {
726 URLCopyToken(cip->user, sizeof(cip->user), hstart, (size_t) (cp - hstart));
727 URLCopyToken(cip->pass, sizeof(cip->pass), cp + 1, (size_t) (at1 - (cp + 1)));
728 }
729 *at1 = '@';
730 h2start = at1 + 1;
731 }
732
733 cp = strchr(h2start, ':');
734 if (cp == NULL) {
735 /* whole thing is the host then */
736 URLCopyToken(cip->host, sizeof(cip->host), h2start, (size_t) (hend - h2start));
737 } else if (strchr(cp + 1, ':') != NULL) {
738 /* Too many colons */
739 return (kMalformedURL);
740 } else {
741 URLCopyToken(cip->host, sizeof(cip->host), h2start, (size_t) (cp - h2start));
742 URLCopyToken(portstr, sizeof(portstr), cp + 1, (size_t) (hend - (cp + 1)));
743 port = atoi(portstr);
744 if (port > 0)
745 cip->port = port;
746 }
747
748 *hend = (char) sc;
749 if ((*hend == '\0') || ((*hend == '/') && (hend[1] == '\0'))) {
750 /* no path, okay */
751 return (0);
752 }
753
754 lastslash = strrchr(hend, '/');
755 if (lastslash == NULL) {
756 /* no path, okay */
757 return (0);
758 }
759 *lastslash = '\0';
760
761 if ((semi = strchr(lastslash + 1, ';')) != NULL) {
762 *semi++ = '\0';
763#ifdef HAVE_STRCASECMP
764 if (strcasecmp(semi, "type=i") == 0) {
765 if (xtype != NULL)
766 *xtype = kTypeBinary;
767 } else if (strcasecmp(semi, "type=a") == 0) {
768 if (xtype != NULL)
769 *xtype = kTypeAscii;
770 } else if (strcasecmp(semi, "type=b") == 0) {
771 if (xtype != NULL)
772 *xtype = kTypeBinary;
773 } else if (strcasecmp(semi, "type=d") == 0) {
774 if (wantnlst != NULL) {
775 *wantnlst = 1;
776 if (xtype != NULL)
777 *xtype = kTypeAscii;
778 } else {
779 /* You didn't want these. */
780 return (kMalformedURL);
781 }
782 }
783#else /* HAVE_STRCASECMP */
784 if (strcmp(semi, "type=i") == 0) {
785 if (xtype != NULL)
786 *xtype = kTypeBinary;
787 } else if (strcmp(semi, "type=a") == 0) {
788 if (xtype != NULL)
789 *xtype = kTypeAscii;
790 } else if (strcmp(semi, "type=b") == 0) {
791 if (xtype != NULL)
792 *xtype = kTypeBinary;
793 } else if (strcmp(semi, "type=d") == 0) {
794 if (wantnlst != NULL) {
795 *wantnlst = 1;
796 if (xtype != NULL)
797 *xtype = kTypeAscii;
798 } else {
799 /* You didn't want these. */
800 return (kMalformedURL);
801 }
802 }
803#endif /* HAVE_STRCASECMP */
804 }
805 URLCopyToken(fn, fnsize, lastslash + 1, strlen(lastslash + 1));
806 for (parsestr = hend; (tok = strtok(parsestr, "/")) != NULL; parsestr = NULL) {
807 URLCopyToken(subdir, sizeof(subdir), tok, strlen(tok));
808 (void) AddLine(cdlist, subdir);
809 }
810 *lastslash = '/';
811 return (kNoErr);
812} /* FTPDecodeURL */
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
char * strtok(char *String, const char *Delimiters)
Definition: utclib.c:338
USHORT port
Definition: uri.c:228
#define strncasecmp
Definition: fake.h:10
#define strcasecmp
Definition: fake.h:9
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
void URLCopyToken(char *dst, size_t dsize, const char *src, size_t howmuch)
Definition: open.c:598
static const WCHAR url[]
Definition: encode.c:1432
#define kTypeAscii
Definition: ncftp.h:353
#define kMalformedURL
Definition: ncftp.h:385
#define kTypeBinary
Definition: ncftp.h:354
char host[64]
Definition: ncftp.h:136
unsigned int port
Definition: ncftp.h:140
char pass[64]
Definition: ncftp.h:138
char user[64]
Definition: ncftp.h:137
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159

Referenced by DecodeDirectoryURL().

◆ FTPDelete()

int FTPDelete ( const FTPCIPtr  cip,
const char *const  pattern,
const int  recurse,
const int  doGlob 
)

Definition at line 195 of file cmds.c.

196{
197 LineList fileList;
198 LinePtr filePtr;
199 char *file;
200 int onceResult, batchResult;
201
202 if (cip == NULL)
203 return (kErrBadParameter);
204 if (strcmp(cip->magic, kLibraryMagic))
205 return (kErrBadMagic);
206
207 batchResult = FTPRemoteGlob(cip, &fileList, pattern, doGlob);
208 if (batchResult != kNoErr)
209 return (batchResult);
210
211 for (batchResult = kNoErr, filePtr = fileList.first;
212 filePtr != NULL;
213 filePtr = filePtr->next)
214 {
215 file = filePtr->line;
216 if (file == NULL) {
217 batchResult = kErrBadLineList;
218 cip->errNo = kErrBadLineList;
219 break;
220 }
221 onceResult = FTPCmd(cip, "DELE %s", file);
222 if (onceResult < 0) {
223 batchResult = onceResult;
224 break;
225 }
226 if (onceResult != 2) {
227 if (recurse != kRecursiveYes) {
228 batchResult = kErrDELEFailed;
229 cip->errNo = kErrDELEFailed;
230 } else {
231 onceResult = FTPCmd(cip, "RMD %s", file);
232 if (onceResult < 0) {
233 batchResult = onceResult;
234 break;
235 }
236 if (onceResult != 2) {
237 onceResult = FTPRmdirRecursive(cip, file);
238 if (onceResult < 0) {
239 batchResult = kErrRMDFailed;
240 cip->errNo = kErrRMDFailed;
241 }
242 }
243 }
244 }
245 }
246 DisposeLineListContents(&fileList);
247 return (batchResult);
248} /* FTPDelete */
static int FTPRmdirRecursive(const FTPCIPtr cip, const char *const dir)
Definition: cmds.c:158
#define kErrDELEFailed
Definition: ncftp_errno.h:61
#define kErrRMDFailed
Definition: ncftp_errno.h:43

Referenced by DeleteCmd(), FTPGetOneF(), FTPPutOneF(), and FTPRmdirRecursiveL2().

◆ FTPEndDataCmd()

int FTPEndDataCmd ( const  FTPCIPtr,
int  didXfer 
)

Definition at line 933 of file rcmd.c.

934{
935 int result;
936 int respCode;
937 ResponsePtr rp;
938
939 if (cip == NULL)
940 return (kErrBadParameter);
941 if (strcmp(cip->magic, kLibraryMagic))
942 return (kErrBadMagic);
943
945 result = kNoErr;
946 if (didXfer) {
947 /* Get the response to the data transferred. Most likely a message
948 * saying that the transfer completed succesfully. However, if
949 * we tried to abort the transfer using ABOR, we will have a response
950 * to that command instead.
951 */
952 rp = InitResponse();
953 if (rp == NULL) {
954 Error(cip, kDontPerror, "Malloc failed.\n");
955 cip->errNo = kErrMallocFailed;
956 result = cip->errNo;
957 return (result);
958 }
959 result = GetResponse(cip, rp);
960 if (result < 0)
961 return (result);
962 respCode = rp->codeType;
963 DoneWithResponse(cip, rp);
964 if (respCode != 2) {
965 cip->errNo = kErrDataTransferFailed;
966 result = cip->errNo;
967 } else {
968 result = kNoErr;
969 }
970 }
971 return (result);
972} /* FTPEndDataCmd */
#define kErrDataTransferFailed
Definition: ncftp_errno.h:78

Referenced by FTPGetOneF(), FTPList(), FTPListToMemory2(), FTPPutOneF(), and FTPStartDataCmd().

◆ FTPFileExists()

int FTPFileExists ( const FTPCIPtr  cip,
const char *const  file 
)

Definition at line 1423 of file cmds.c.

1424{
1425 return (FTPFileExists2(cip, file, 1, 1, 1, 1, 1));
1426} /* FTPFileExists */
int FTPFileExists2(const FTPCIPtr cip, const char *const file, const int tryMDTM, const int trySIZE, const int tryMLST, const int trySTAT, const int tryNLST)
Definition: cmds.c:1350

◆ FTPFileExists2()

int FTPFileExists2 ( const FTPCIPtr  cip,
const char *const  file,
const int  tryMDTM,
const int  trySIZE,
const int  tryMLST,
const int  trySTAT,
const int  tryNLST 
)

Definition at line 1350 of file cmds.c.

1351{
1352 int result;
1353 time_t mdtm;
1355 MLstItem mlsInfo;
1356
1357 if (tryMDTM != 0) {
1358 result = FTPFileModificationTime(cip, file, &mdtm);
1359 if (result == kNoErr)
1360 return (kNoErr);
1361 if (result == kErrMDTMFailed) {
1364 }
1365 /* else keep going */
1366 }
1367
1368 if (trySIZE != 0) {
1370 if (result == kNoErr)
1371 return (kNoErr);
1372 /* SIZE could fail if the server does
1373 * not support it for directories.
1374 *
1375 * if (result == kErrSIZEFailed)
1376 * return (kErrNoSuchFileOrDirectory);
1377 */
1378 /* else keep going */
1379 }
1380
1381
1382 if (tryMLST != 0) {
1383 result = FTPMListOneFile(cip, file, &mlsInfo);
1384 if (result == kNoErr)
1385 return (kNoErr);
1386 if (result == kErrMLSTFailed) {
1389 }
1390 /* else keep going */
1391 }
1392
1393 if (trySTAT != 0) {
1395 if (result == kNoErr)
1396 return (kNoErr);
1397 if (result == kErrSTATFailed) {
1400 }
1401 /* else keep going */
1402 }
1403
1404 if (tryNLST != 0) {
1406 if (result == kNoErr)
1407 return (kNoErr);
1408 if (result == kErrNLSTFailed) {
1411 }
1412 /* else keep going */
1413 }
1414
1416 return (kErrCantTellIfFileExists);
1417} /* FTPFileExists2 */
__kernel_time_t time_t
Definition: linux.h:252
int FTPMListOneFile(const FTPCIPtr cip, const char *const file, const MLstItemPtr mlip)
Definition: cmds.c:947
int FTPFileExistsStat(const FTPCIPtr cip, const char *const file)
Definition: cmds.c:1008
int FTPFileModificationTime(const FTPCIPtr cip, const char *const file, time_t *const mdtm)
Definition: cmds.c:649
int FTPFileExistsNlst(const FTPCIPtr cip, const char *const file)
Definition: cmds.c:1209
int FTPFileSize(const FTPCIPtr cip, const char *const file, longest_int *const size, const int type)
Definition: cmds.c:887
#define longest_int
Definition: ncftp.h:68
#define kErrMDTMFailed
Definition: ncftp_errno.h:63
#define kErrCantTellIfFileExists
Definition: ncftp_errno.h:106
#define kErrNoSuchFileOrDirectory
Definition: ncftp_errno.h:105
#define kErrMLSTFailed
Definition: ncftp_errno.h:97
#define kErrNLSTFailed
Definition: ncftp_errno.h:103
#define kErrSTATFailed
Definition: ncftp_errno.h:101

Referenced by FTPFileExists(), FTPFileType(), and FTPPutOneF().

◆ FTPFileExistsNlst()

int FTPFileExistsNlst ( const FTPCIPtr  cip,
const char *const  file 
)

Definition at line 1209 of file cmds.c.

1210{
1211 int result;
1212 LineList fileList, rootFileList;
1213 char savedCwd[512];
1214
1215 if (cip == NULL)
1216 return (kErrBadParameter);
1217 if (strcmp(cip->magic, kLibraryMagic))
1218 return (kErrBadMagic);
1219
1220 if (file == NULL)
1221 return (kErrBadParameter);
1222
1225 return (result);
1226 }
1227
1229 /* First, make sure that when we NLST a pathname
1230 * that does not exist, that we get an error back.
1231 *
1232 * We also assume that a valid NLST response has
1233 * at least 3 lines of response text, typically
1234 * a "start" line, intermediate data, and then
1235 * a trailing line.
1236 *
1237 * We also can see a one-line case.
1238 */
1239 if (
1240 ((FTPListToMemory2(cip, "NoSuchFile", &fileList, "", 0, (int *) 0)) == kNoErr) &&
1241 (fileList.nLines >= 1) &&
1242 (strstr(fileList.last->line, "o such file") == NULL) &&
1243 (strstr(fileList.last->line, "ot found") == NULL) &&
1244 (strstr(fileList.last->line, "o Such File") == NULL) &&
1245 (strstr(fileList.last->line, "ot Found") == NULL)
1246
1247 ) {
1250 DisposeLineListContents(&fileList);
1251 return (result);
1252 }
1253 DisposeLineListContents(&fileList);
1254
1255 /* We can't assume that we can simply say NLST rootdir/firstfile,
1256 * since the remote host may not be using / as a directory
1257 * delimiter. So we have to change to the root directory
1258 * and then do the NLST on that file.
1259 */
1260 if (
1261 (FTPGetCWD(cip, savedCwd, sizeof(savedCwd)) != kNoErr) ||
1263 ) {
1264 return (cip->errNo);
1265 }
1266
1267 /* OK, we get an error when we list
1268 * a non-existant file, but now we need to
1269 * see if we get a positive reply when
1270 * we stat a file that does exist.
1271 *
1272 * To do this, we list the root directory,
1273 * which we assume has one or more items.
1274 * If it doesn't, the user can't do anything
1275 * anyway. Then we do the first item
1276 * we found to see if NLST says it exists.
1277 */
1278 if (
1279 ((result = FTPListToMemory2(cip, "", &rootFileList, "", 0, (int *) 0)) < 0) ||
1280 (rootFileList.last == NULL) ||
1281 (rootFileList.last->line == NULL)
1282 ) {
1283 /* Hmmm... well, in any case we can't use NLST. */
1286 DisposeLineListContents(&rootFileList);
1287 (void) FTPChdir(cip, savedCwd);
1288 return (result);
1289 }
1290
1291 if (
1292 ((FTPListToMemory2(cip, rootFileList.last->line, &fileList, "", 0, (int *) 0)) == kNoErr) &&
1293 (fileList.nLines >= 1) &&
1294 (strstr(fileList.last->line, "o such file") == NULL) &&
1295 (strstr(fileList.last->line, "ot found") == NULL) &&
1296 (strstr(fileList.last->line, "o Such File") == NULL) &&
1297 (strstr(fileList.last->line, "ot Found") == NULL)
1298
1299 ) {
1300 /* Good. We listed the item. */
1301 DisposeLineListContents(&fileList);
1302 DisposeLineListContents(&rootFileList);
1304
1305 /* Don't forget to change back to the original directory. */
1306 (void) FTPChdir(cip, savedCwd);
1307 } else {
1310 DisposeLineListContents(&fileList);
1311 DisposeLineListContents(&rootFileList);
1312 (void) FTPChdir(cip, savedCwd);
1313 return (result);
1314 }
1315 }
1316
1317 /* Check the requested item. */
1318 InitLineList(&fileList);
1319 if (
1320 ((FTPListToMemory2(cip, file, &fileList, "", 0, (int *) 0)) == kNoErr) &&
1321 (fileList.nLines >= 1) &&
1322 (strstr(fileList.last->line, "o such file") == NULL) &&
1323 (strstr(fileList.last->line, "ot found") == NULL) &&
1324 (strstr(fileList.last->line, "o Such File") == NULL) &&
1325 (strstr(fileList.last->line, "ot Found") == NULL)
1326
1327 ) {
1328 /* The item existed. */
1329 result = kNoErr;
1330 } else {
1331 cip->errNo = kErrNLSTFailed;
1333 }
1334
1335 DisposeLineListContents(&fileList);
1336 return (result);
1337} /* FTPFileExistsNlst*/
int FTPListToMemory2(const FTPCIPtr cip, const char *const pattern, const LineListPtr llines, const char *const lsflags, const int blankLines, int *const tryMLSD)
Definition: io.c:366
#define kCommandAvailable
Definition: ncftp.h:380
#define kCommandAvailabilityUnknown
Definition: ncftp.h:379
#define kCommandNotAvailable
Definition: ncftp.h:381
#define kErrNLSTwithFileNotAvailable
Definition: ncftp_errno.h:104
char * startingWorkingDirectory
Definition: ncftp.h:158
int NLSTfileParamWorks
Definition: ncftp.h:180
int nLines
Definition: ncftp.h:86
LinePtr last
Definition: ncftp.h:85

Referenced by FTPFileExists2().

◆ FTPFileExistsStat()

int FTPFileExistsStat ( const FTPCIPtr  cip,
const char *const  file 
)

Definition at line 1008 of file cmds.c.

1009{
1010 int result;
1011 ResponsePtr rp;
1012 LineList fileList;
1013 char savedCwd[512];
1014
1015 if (cip == NULL)
1016 return (kErrBadParameter);
1017 if (strcmp(cip->magic, kLibraryMagic))
1018 return (kErrBadMagic);
1019
1020 if (file == NULL)
1021 return (kErrBadParameter);
1022
1025 return (result);
1026 }
1027
1029 rp = InitResponse();
1030 if (rp == NULL) {
1032 cip->errNo = kErrMallocFailed;
1033 Error(cip, kDontPerror, "Malloc failed.\n");
1034 return (result);
1035
1036 }
1037
1038 /* First, make sure that when we STAT a pathname
1039 * that does not exist, that we get an error back.
1040 *
1041 * We also assume that a valid STAT response has
1042 * at least 3 lines of response text, typically
1043 * a "start" line, intermediate data, and then
1044 * a trailing line.
1045 *
1046 * We also can see a one-line case.
1047 */
1048 result = RCmd(cip, rp, "STAT %s", "NoSuchFile");
1049 if ((result == 2) && ((rp->msg.nLines >= 3) || (rp->msg.nLines == 1))) {
1050 /* Hmmm.... it gave back a positive
1051 * response. So STAT <file> does not
1052 * work correctly.
1053 */
1054 if (
1055 (rp->msg.first->next != NULL) &&
1056 (rp->msg.first->next->line != NULL) &&
1057 (
1058 (strstr(rp->msg.first->next->line, "o such file") != NULL) ||
1059 (strstr(rp->msg.first->next->line, "ot found") != NULL)
1060 )
1061 ) {
1062 /* OK, while we didn't want a 200
1063 * level response, some servers,
1064 * like wu-ftpd print an error
1065 * message "No such file or
1066 * directory" which we can special
1067 * case.
1068 */
1069 result = kNoErr;
1070 } else {
1073 DoneWithResponse(cip, rp);
1074 return (result);
1075 }
1076 }
1077 DoneWithResponse(cip, rp);
1078
1079 /* We can't assume that we can simply say STAT rootdir/firstfile,
1080 * since the remote host may not be using / as a directory
1081 * delimiter. So we have to change to the root directory
1082 * and then do the STAT on that file.
1083 */
1084 if (
1085 (FTPGetCWD(cip, savedCwd, sizeof(savedCwd)) != kNoErr) ||
1087 ) {
1088 return (cip->errNo);
1089 }
1090
1091 /* OK, we get an error when we stat
1092 * a non-existant file, but now we need to
1093 * see if we get a positive reply when
1094 * we stat a file that does exist.
1095 *
1096 * To do this, we list the root directory,
1097 * which we assume has one or more items.
1098 * If it doesn't, the user can't do anything
1099 * anyway. Then we stat the first item
1100 * we found to see if STAT says it exists.
1101 */
1102 if (
1103 ((result = FTPListToMemory2(cip, "", &fileList, "", 0, (int *) 0)) < 0) ||
1104 (fileList.last == NULL) ||
1105 (fileList.last->line == NULL)
1106 ) {
1107 /* Hmmm... well, in any case we can't use STAT. */
1110 DisposeLineListContents(&fileList);
1111 (void) FTPChdir(cip, savedCwd);
1112 return (result);
1113 }
1114
1115 rp = InitResponse();
1116 if (rp == NULL) {
1118 cip->errNo = kErrMallocFailed;
1119 Error(cip, kDontPerror, "Malloc failed.\n");
1120 DisposeLineListContents(&fileList);
1121 (void) FTPChdir(cip, savedCwd);
1122 return (result);
1123
1124 }
1125
1126 result = RCmd(cip, rp, "STAT %s", fileList.last->line);
1127 DisposeLineListContents(&fileList);
1128
1129 if ((result != 2) || (rp->msg.nLines == 2)) {
1130 /* Hmmm.... it gave back a negative
1131 * response. So STAT <file> does not
1132 * work correctly.
1133 */
1136 DoneWithResponse(cip, rp);
1137 (void) FTPChdir(cip, savedCwd);
1138 return (result);
1139 } else if (
1140 (rp->msg.first->next != NULL) &&
1141 (rp->msg.first->next->line != NULL) &&
1142 (
1143 (strstr(rp->msg.first->next->line, "o such file") != NULL) ||
1144 (strstr(rp->msg.first->next->line, "ot found") != NULL)
1145 )
1146 ) {
1147 /* Same special-case of the second line of STAT response. */
1150 DoneWithResponse(cip, rp);
1151 (void) FTPChdir(cip, savedCwd);
1152 return (result);
1153 }
1154 DoneWithResponse(cip, rp);
1156
1157 /* Don't forget to change back to the original directory. */
1158 (void) FTPChdir(cip, savedCwd);
1159 }
1160
1161 rp = InitResponse();
1162 if (rp == NULL) {
1164 cip->errNo = kErrMallocFailed;
1165 Error(cip, kDontPerror, "Malloc failed.\n");
1166 return (result);
1167 }
1168
1169 result = RCmd(cip, rp, "STAT %s", file);
1170 if (result == 2) {
1171 result = kNoErr;
1172 if (((rp->msg.nLines >= 3) || (rp->msg.nLines == 1))) {
1173 if (
1174 (rp->msg.first->next != NULL) &&
1175 (rp->msg.first->next->line != NULL) &&
1176 (
1177 (strstr(rp->msg.first->next->line, "o such file") != NULL) ||
1178 (strstr(rp->msg.first->next->line, "ot found") != NULL)
1179 )
1180 ) {
1181 cip->errNo = kErrSTATFailed;
1183 } else {
1184 result = kNoErr;
1185 }
1186 } else if (rp->msg.nLines == 2) {
1187 cip->errNo = kErrSTATFailed;
1189 } else {
1190 result = kNoErr;
1191 }
1192 } else {
1193 cip->errNo = kErrSTATFailed;
1195 }
1196 DoneWithResponse(cip, rp);
1197 return (result);
1198} /* FTPFileExistsStat */
#define kErrSTATwithFileNotAvailable
Definition: ncftp_errno.h:102
int STATfileParamWorks
Definition: ncftp.h:179

Referenced by FTPFileExists2().

◆ FTPFileModificationTime()

int FTPFileModificationTime ( const FTPCIPtr  cip,
const char *const  file,
time_t *const  mdtm 
)

Definition at line 649 of file cmds.c.

650{
651 int result;
652 ResponsePtr rp;
653
654 if (cip == NULL)
655 return (kErrBadParameter);
656 if (strcmp(cip->magic, kLibraryMagic))
657 return (kErrBadMagic);
658
659 if ((mdtm == NULL) || (file == NULL))
660 return (kErrBadParameter);
661 *mdtm = kModTimeUnknown;
662
663 if (cip->hasMDTM == kCommandNotAvailable) {
666 } else {
667 rp = InitResponse();
668 if (rp == NULL) {
670 cip->errNo = kErrMallocFailed;
671 Error(cip, kDontPerror, "Malloc failed.\n");
672 } else {
673 result = RCmd(cip, rp, "MDTM %s", file);
674 if (result < 0) {
675 DoneWithResponse(cip, rp);
676 return (result);
677 } else if (strncmp(rp->msg.first->line, "19100", 5) == 0) {
678 Error(cip, kDontPerror, "Warning: Server has Y2K Bug in \"MDTM\" command.\n");
679 cip->errNo = kErrMDTMFailed;
681 } else if (result == 2) {
682 *mdtm = UnMDTMDate(rp->msg.first->line);
684 result = kNoErr;
685 } else if (UNIMPLEMENTED_CMD(rp->code)) {
689 } else {
690 cip->errNo = kErrMDTMFailed;
692 }
693 DoneWithResponse(cip, rp);
694 }
695 }
696 return (result);
697} /* FTPFileModificationTime */
#define UNIMPLEMENTED_CMD(a)
Definition: ncftp.h:373
#define kModTimeUnknown
Definition: ncftp.h:377
time_t UnMDTMDate(char *)
Definition: util.c:486
#define kErrMDTMNotAvailable
Definition: ncftp_errno.h:66
int code
Definition: ncftp.h:92

Referenced by FTPFileExists2(), FTPFileSizeAndModificationTime(), and FTPGetOneF().

◆ FTPFileSize()

int FTPFileSize ( const FTPCIPtr  cip,
const char *const  file,
longest_int *const  size,
const int  type 
)

Definition at line 887 of file cmds.c.

888{
889 int result;
890 ResponsePtr rp;
891
892 if (cip == NULL)
893 return (kErrBadParameter);
894 if (strcmp(cip->magic, kLibraryMagic))
895 return (kErrBadMagic);
896
897 if ((size == NULL) || (file == NULL))
898 return (kErrBadParameter);
900
902 if (result < 0)
903 return (result);
904
905 if (cip->hasSIZE == kCommandNotAvailable) {
908 } else {
909 rp = InitResponse();
910 if (rp == NULL) {
912 cip->errNo = kErrMallocFailed;
913 Error(cip, kDontPerror, "Malloc failed.\n");
914 } else {
915 result = RCmd(cip, rp, "SIZE %s", file);
916 if (result < 0) {
917 DoneWithResponse(cip, rp);
918 return (result);
919 } else if (result == 2) {
920#if defined(HAVE_LONG_LONG) && defined(SCANF_LONG_LONG)
922#elif defined(HAVE_LONG_LONG) && defined(HAVE_STRTOQ)
923 *size = (longest_int) strtoq(rp->msg.first->line, NULL, 0);
924#else
925 (void) sscanf(rp->msg.first->line, "%ld", size);
926#endif
928 result = kNoErr;
929 } else if (UNIMPLEMENTED_CMD(rp->code)) {
933 } else {
934 cip->errNo = kErrSIZEFailed;
936 }
937 DoneWithResponse(cip, rp);
938 }
939 }
940 return (result);
941} /* FTPFileSize */
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define SCANF_LONG_LONG
Definition: wincfg.h:30
int FTPSetTransferType(const FTPCIPtr cip, int type)
Definition: cmds.c:836
#define kSizeUnknown
Definition: ncftp.h:376
#define kErrSIZENotAvailable
Definition: ncftp_errno.h:65
#define kErrSIZEFailed
Definition: ncftp_errno.h:62

Referenced by FTPFileExists2(), and FTPFileSizeAndModificationTime().

◆ FTPFileSizeAndModificationTime()

int FTPFileSizeAndModificationTime ( const FTPCIPtr  cip,
const char *const  file,
longest_int *const  size,
const int  type,
time_t *const  mdtm 
)

Definition at line 1433 of file cmds.c.

1434{
1435 MLstItem mlsInfo;
1436 int result;
1437
1438 if (cip == NULL)
1439 return (kErrBadParameter);
1440 if (strcmp(cip->magic, kLibraryMagic))
1441 return (kErrBadMagic);
1442
1443 if ((mdtm == NULL) || (size == NULL) || (file == NULL))
1444 return (kErrBadParameter);
1445
1446 *mdtm = kModTimeUnknown;
1447 *size = kSizeUnknown;
1448
1450 if (result < 0)
1451 return (result);
1452
1453 result = FTPMListOneFile(cip, file, &mlsInfo);
1454 if (result < 0) {
1455 /* Do it the regular way, where
1456 * we do a SIZE and then a MDTM.
1457 */
1458 result = FTPFileSize(cip, file, size, type);
1459 if (result < 0)
1460 return (result);
1461 result = FTPFileModificationTime(cip, file, mdtm);
1462 return (result);
1463 } else {
1464 *mdtm = mlsInfo.ftime;
1465 *size = mlsInfo.fsize;
1466 }
1467
1468 return (result);
1469} /* FTPFileSizeAndModificationTime */
longest_int fsize
Definition: ncftp.h:279
time_t ftime
Definition: ncftp.h:280

Referenced by FTPGetOneF(), and FTPPutOneF().

◆ FTPFileType()

int FTPFileType ( const FTPCIPtr  cip,
const char *const  file,
int *const  ftype 
)

Definition at line 1475 of file cmds.c.

1476{
1477 int result;
1478 MLstItem mlsInfo;
1479
1480 if (cip == NULL)
1481 return (kErrBadParameter);
1482 if (strcmp(cip->magic, kLibraryMagic))
1483 return (kErrBadMagic);
1484
1485 if ((file == NULL) || (file[0] == '\0')) {
1486 cip->errNo = kErrBadParameter;
1487 return (kErrBadParameter);
1488 }
1489
1490 if (ftype == NULL) {
1491 cip->errNo = kErrBadParameter;
1492 return (kErrBadParameter);
1493 }
1494
1495 *ftype = 0;
1496 result = FTPMListOneFile(cip, file, &mlsInfo);
1497 if (result == kNoErr) {
1498 *ftype = mlsInfo.ftype;
1499 return (kNoErr);
1500 }
1501
1502 /* Preserve old working directory. */
1503 (void) FTPGetCWD(cip, cip->buf, cip->bufSize);
1504
1505 result = FTPChdir(cip, file);
1506 if (result == kNoErr) {
1507 *ftype = 'd';
1508 /* Yes it was a directory, now go back to
1509 * where we were.
1510 */
1511 (void) FTPChdir(cip, cip->buf);
1512
1513 /* Note: This improperly assumes that we
1514 * will be able to chdir back, which is
1515 * not guaranteed.
1516 */
1517 return (kNoErr);
1518 }
1519
1520 result = FTPFileExists2(cip, file, 1, 1, 0, 1, 1);
1523
1524 return (result);
1525} /* FTPFileType */
#define kErrFileExistsButCannotDetermineType
Definition: ncftp_errno.h:107
int ftype
Definition: ncftp.h:278

Referenced by FTPIsDir(), and FTPIsRegularFile().

◆ FTPFtw()

int FTPFtw ( const FTPCIPtr  cip,
const char *const  dir,
FTPFtwProc  proc,
int  maxdepth 
)

Definition at line 1706 of file glob.c.

1707{
1708 int result, result2;
1709 char *cp;
1710 char savedcwd[1024];
1711 char curcwd[2048];
1712
1713 result = FTPIsDir(cip, dir);
1714 if (result < 0) {
1715 /* error */
1716 return result;
1717 } else if (result == 0) {
1719 return (result);
1720 }
1721
1722 /* Preserve old working directory. */
1723 (void) FTPGetCWD(cip, savedcwd, sizeof(savedcwd));
1724
1725 result = FTPChdir(cip, dir);
1726 if (result != kNoErr) {
1727 return (result);
1728 }
1729
1730 /* Get full working directory we just changed to. */
1731 result = FTPGetCWD(cip, curcwd, sizeof(curcwd) - 3);
1732 if (result != kNoErr) {
1733 if (FTPChdir(cip, savedcwd) != kNoErr) {
1736 }
1737 return (result);
1738 }
1739
1740 result2 = (*proc)(cip, curcwd, kFtwDir);
1741 if (result2 == kNoErr) {
1742 cp = curcwd + strlen(curcwd);
1743
1744 if ((strchr(curcwd, '/') == NULL) && (strrchr(curcwd, '\\') != NULL))
1745 *cp++ = '\\';
1746 else
1747 *cp++ = '/';
1748 *cp = '\0';
1749 result = FTPFtwL2(cip, curcwd, cp, sizeof(curcwd), proc, maxdepth - 1);
1750 }
1751
1752
1753 if (FTPChdir(cip, savedcwd) != kNoErr) {
1754 /* Could not cd back to the original user directory -- bad. */
1756 cip->errNo = kErrCannotGoToPrevDir;
1757 return (result);
1758 }
1759
1760 if ((result2 != kNoErr) && (result == kNoErr))
1761 result = result2;
1762
1763 return (result);
1764} /* FTPFtw */
unsigned int dir
Definition: maze.c:112
static int FTPFtwL2(const FTPCIPtr cip, char *dir, char *end, size_t dirsize, FTPFtwProc proc, int maxdepth)
Definition: glob.c:1624
int FTPIsDir(const FTPCIPtr cip, const char *const dir)
Definition: cmds.c:1531
#define kFtwDir
Definition: ncftp.h:414
#define kErrNotADirectory
Definition: ncftp_errno.h:108
#define kErrCannotGoToPrevDir
Definition: ncftp_errno.h:58
static HANDLE proc()
Definition: pdb.c:34

◆ FTPGetCWD()

int FTPGetCWD ( const FTPCIPtr  cip,
char *const  newCwd,
const size_t  newCwdSize 
)

Definition at line 254 of file cmds.c.

255{
256 ResponsePtr rp;
257 char *l, *r;
258 int result;
259
260 if (cip == NULL)
261 return (kErrBadParameter);
262 if (strcmp(cip->magic, kLibraryMagic))
263 return (kErrBadMagic);
264
265 if ((newCwd == NULL) || (newCwdSize == 0)) {
268 } else {
269 rp = InitResponse();
270 if (rp == NULL) {
272 cip->errNo = kErrMallocFailed;
273 Error(cip, kDontPerror, "Malloc failed.\n");
274 } else {
275 result = RCmd(cip, rp, "PWD");
276 if (result == 2) {
277 if ((r = strrchr(rp->msg.first->line, '"')) != NULL) {
278 /* "xxxx" is current directory.
279 * Strip out just the xxxx to copy into the remote cwd.
280 */
281 l = strchr(rp->msg.first->line, '"');
282 if ((l != NULL) && (l != r)) {
283 *r = '\0';
284 ++l;
285 (void) Strncpy(newCwd, l, newCwdSize);
286 *r = '"'; /* Restore, so response prints correctly. */
287 }
288 } else {
289 /* xxxx is current directory.
290 * Mostly for VMS.
291 */
292 if ((r = strchr(rp->msg.first->line, ' ')) != NULL) {
293 *r = '\0';
294 (void) Strncpy(newCwd, (rp->msg.first->line), newCwdSize);
295 *r = ' '; /* Restore, so response prints correctly. */
296 }
297 }
298 result = kNoErr;
299 } else if (result > 0) {
301 cip->errNo = kErrPWDFailed;
302 }
303 DoneWithResponse(cip, rp);
304 }
305 }
306 return (result);
307} /* FTPGetCWD */
#define kErrPWDFailed
Definition: ncftp_errno.h:41

Referenced by FTPChdir3(), FTPChdirAndGetCWD(), FTPFileExistsNlst(), FTPFileExistsStat(), FTPFileType(), FTPFtw(), FTPLoginHost(), FTPMkdir2(), FTPRemoteRecursiveFileList(), FTPRemoteRecursiveFileList1(), FTPRmdirRecursive(), nFTPChdirAndGetCWD(), OpenCmd(), OpenURL(), and PwdCmd().

◆ FTPGetFiles()

int FTPGetFiles ( const FTPCIPtr  cip,
const char *const  pattern,
const char *const  dstdir,
const int  recurse,
const int  doGlob 
)

Definition at line 2730 of file io.c.

2731{
2732 return (FTPGetFiles3(cip, pattern, dstdir, recurse, doGlob, kTypeBinary, kResumeNo, kAppendNo, kDeleteNo, kTarYes, (ConfirmResumeDownloadProc) 0, 0));
2733} /* FTPGetFiles */
int FTPGetFiles3(const FTPCIPtr cip, const char *pattern1, const char *const dstdir1, const int recurse, int doGlob, const int xtype, const int resumeflag, int appendflag, const int deleteflag, const int tarflag, const ConfirmResumeDownloadProc resumeProc, int UNUSED(reserved))
Definition: io.c:2486
#define kDeleteNo
Definition: ncftp.h:369
#define kTarYes
Definition: ncftp.h:370
#define kAppendNo
Definition: ncftp.h:365
int(* ConfirmResumeDownloadProc)(const char *volatile *localpath, volatile longest_int localsize, volatile time_t localmtime, const char *volatile remotepath, volatile longest_int remotesize, volatile time_t remotetime, volatile longest_int *volatile startPoint)
Definition: ncftp.h:431
#define kResumeNo
Definition: ncftp.h:367

◆ FTPGetFiles2()

int FTPGetFiles2 ( const FTPCIPtr  cip,
const char *const  pattern,
const char *const  dstdir,
const int  recurse,
const int  doGlob,
const int  xtype,
const int  resumeflag,
const int  appendflag 
)

Definition at line 2739 of file io.c.

2740{
2741 return (FTPGetFiles3(cip, pattern, dstdir, recurse, doGlob, xtype, resumeflag, appendflag, kDeleteNo, kTarYes, (ConfirmResumeDownloadProc) 0, 0));
2742} /* FTPGetFiles2 */

◆ FTPGetFiles3()

int FTPGetFiles3 ( const FTPCIPtr  cip,
const char pattern,
const char *const  dstdir,
const int  recurse,
int  doGlob,
const int  xtype,
const int  resumeflag,
int  appendflag,
const int  deleteflag,
const int  tarflag,
const ConfirmResumeDownloadProc  resumeProc,
int  reserved 
)

◆ FTPGetFilesAscii()

int FTPGetFilesAscii ( const FTPCIPtr  cip,
const char *const  pattern,
const char *const  dstdir,
const int  recurse,
const int  doGlob 
)

Definition at line 2757 of file io.c.

2758{
2759 return (FTPGetFiles3(cip, pattern, dstdir, recurse, doGlob, kTypeAscii, kResumeNo, kAppendNo, kDeleteNo, kTarNo, (ConfirmResumeDownloadProc) 0, 0));
2760} /* FTPGetFilesAscii */
#define kTarNo
Definition: ncftp.h:371

◆ FTPGetLocalCWD()

char * FTPGetLocalCWD ( char buf,
size_t  size 
)

Definition at line 29 of file util.c.

30{
31#ifdef HAVE_GETCWD
32 static char *cwdBuf = NULL;
33 static size_t cwdBufSize = 0;
34
35 if (cwdBufSize == 0) {
36 cwdBufSize = (size_t) 128;
37 cwdBuf = (char *) malloc(cwdBufSize);
38 }
39
40 for (errno = 0; ; ) {
41 if (cwdBuf == NULL) {
42 return NULL;
43 }
44
45 if (getcwd(cwdBuf, cwdBufSize) != NULL)
46 break;
47 if (errno != ERANGE) {
48 (void) Strncpy(buf, ".", size);
49 return NULL;
50 }
51 cwdBufSize *= 2;
52 cwdBuf = (char *) Realloc(cwdBuf, cwdBufSize);
53 }
54
55 return (Strncpy(buf, cwdBuf, size));
56#else
57#ifdef HAVE_GETWD
58 static char *cwdBuf = NULL;
59 char *dp;
60
61 /* Due to the way getwd is usually implemented, it's
62 * important to have a buffer large enough to hold the
63 * whole thing. getwd usually starts at the end of the
64 * buffer, and works backwards, returning you a pointer
65 * to the beginning of it when it finishes.
66 */
67 if (size < MAXPATHLEN) {
68 /* Buffer not big enough, so use a temporary one,
69 * and then copy the first 'size' bytes of the
70 * temporary buffer to your 'buf.'
71 */
72 if (cwdBuf == NULL) {
73 cwdBuf = (char *) malloc((size_t) MAXPATHLEN);
74 if (cwdBuf == NULL) {
75 return NULL;
76 }
77 }
78 dp = cwdBuf;
79 } else {
80 /* Buffer is big enough already. */
81 dp = buf;
82 }
83 *dp = '\0';
84 if (getwd(dp) == NULL) {
85 /* getwd() should write the reason why in the buffer then,
86 * according to the man pages.
87 */
88 (void) Strncpy(buf, ".", size);
89 return (NULL);
90 }
91 return (Strncpy(buf, dp, size));
92
93#elif defined(WIN32) || defined(_WINDOWS)
94 if (GetCurrentDirectory((DWORD) size - 1, buf) < 1)
95 return NULL;
96 buf[size - 1] = '\0';
97 return buf;
98#else
99 /* Not a solution, but does anybody not have either of
100 * getcwd or getwd?
101 */
102 --Error--;
103#endif
104#endif
105} /* GetCWD */
#define ERANGE
Definition: acclib.h:92
_Check_return_ _Ret_opt_z_ _CRTIMP char *__cdecl getcwd(_Out_writes_opt_(_SizeInBytes) char *_DstBuf, _In_ int _SizeInBytes)
__kernel_size_t size_t
Definition: linux.h:237
#define getwd
Definition: fake.h:7
unsigned long DWORD
Definition: ntddk_ex.h:95
#define MAXPATHLEN
Definition: ftp_var.h:35
void * Realloc(void *, size_t)
#define errno
Definition: errno.h:18
#define GetCurrentDirectory
Definition: winbase.h:3805

Referenced by DoOpen(), LocalChdirCmd(), LocalPwdCmd(), PostInit(), SpoolGetCmd(), SpoolPutCmd(), and SpoolX().

◆ FTPGetOneFile()

int FTPGetOneFile ( const FTPCIPtr  cip,
const char *const  file,
const char *const  dstfile 
)

Definition at line 2712 of file io.c.

2713{
2715} /* FTPGetOneFile */
int FTPGetOneFile3(const FTPCIPtr cip, const char *const file, const char *const dstfile, const int xtype, const int fdtouse, const int resumeflag, const int appendflag, const int deleteflag, const ConfirmResumeDownloadProc resumeProc, int UNUSED(reserved))
Definition: io.c:2451

◆ FTPGetOneFile2()

int FTPGetOneFile2 ( const FTPCIPtr  cip,
const char *const  file,
const char *const  dstfile,
const int  xtype,
const int  fdtouse,
const int  resumeflag,
const int  appendflag 
)

Definition at line 2721 of file io.c.

2722{
2723 return (FTPGetOneFile3(cip, file, dstfile, xtype, fdtouse, resumeflag, appendflag, kDeleteNo, (ConfirmResumeDownloadProc) 0, 0));
2724} /* FTPGetOneFile2 */

Referenced by CatCmd(), and PageCmd().

◆ FTPGetOneFile3()

int FTPGetOneFile3 ( const FTPCIPtr  cip,
const char *const  file,
const char *const  dstfile,
const int  xtype,
const int  fdtouse,
const int  resumeflag,
const int  appendflag,
const int  deleteflag,
const ConfirmResumeDownloadProc  resumeProc,
int  reserved 
)

◆ FTPGetOneFileAscii()

int FTPGetOneFileAscii ( const FTPCIPtr  cip,
const char *const  file,
const char *const  dstfile 
)

Definition at line 2748 of file io.c.

2749{
2751} /* FTPGetOneFileAscii */

◆ FTPInitConnectionInfo()

int FTPInitConnectionInfo ( const FTPLIPtr  lip,
const FTPCIPtr  cip,
size_t  bufsize 
)

Definition at line 984 of file open.c.

985{
986 size_t siz;
987
988 if ((lip == NULL) || (cip == NULL) || (bufSize == 0))
989 return (kErrBadParameter);
990
991 siz = sizeof(FTPConnectionInfo);
992 (void) memset(cip, 0, siz);
993
994 if (strcmp(lip->magic, kLibraryMagic))
995 return (kErrBadMagic);
996
997 cip->buf = NULL; /* denote that it needs to be allocated. */
998 cip->bufSize = bufSize;
999 cip->port = lip->defaultPort;
1000 cip->firewallPort = lip->defaultPort;
1011 cip->lip = lip;
1033 (void) STRNCPY(cip->user, "anonymous");
1034 return (kNoErr);
1035} /* FTPInitConnectionInfo */
#define STRNCPY(dst, src, n)
Definition: rdesktop.h:168
GLuint GLsizei bufSize
Definition: glext.h:6040
#define kDefaultCtrlTimeout
Definition: ncftp.h:322
#define kDefaultMaxDials
Definition: ncftp.h:341
#define kFirewallNotInUse
Definition: ncftp.h:388
#define kDefaultRedialDelay
Definition: ncftp.h:342
#define kSendPortMode
Definition: ncftp.h:295
#define kDefaultConnTimeout
Definition: ncftp.h:321
#define kDefaultXferTimeout
Definition: ncftp.h:320
#define kDefaultAbortTimeout
Definition: ncftp.h:323
int firewallType
Definition: ncftp.h:221
unsigned int firewallPort
Definition: ncftp.h:220
int hasRETRBUFSIZE
Definition: ncftp.h:171
unsigned int xferTimeout
Definition: ncftp.h:141
unsigned int connTimeout
Definition: ncftp.h:142
int dataPortMode
Definition: ncftp.h:152
int hasSTORBUFSIZE
Definition: ncftp.h:174
FTPLIPtr lip
Definition: ncftp.h:149
char magic[16]
Definition: ncftp.h:114
unsigned int defaultPort
Definition: ncftp.h:117

Referenced by InitConnectionInfo().

◆ FTPInitializeAnonPassword()

void FTPInitializeAnonPassword ( const  FTPLIPtr)

Definition at line 81 of file open.c.

82{
83 if (lip == NULL)
84 return;
85 if (strcmp(lip->magic, kLibraryMagic))
86 return;
87
89
90 if (lip->defaultAnonPassword[0] == '\0') {
91#ifdef SPAM_PROBLEM_HAS_BEEN_SOLVED_FOREVER
92 GetUsrName(lip->defaultAnonPassword, sizeof(lip->defaultAnonPassword));
93 (void) STRNCAT(lip->defaultAnonPassword, "@");
94
95 /* Default to the "user@" notation
96 * supported by NcFTPd and wu-ftpd.
97 */
98 if (lip->htried > 0)
99 (void) STRNCAT(lip->defaultAnonPassword, lip->ourHostName);
100#else
101 (void) STRNCPY(lip->defaultAnonPassword, "NcFTP@");
102#endif
103 }
104} /* FTPInitializeAnonPassword */
#define STRNCAT(d, s)
Definition: Strn.h:48
void FTPInitializeOurHostName(const FTPLIPtr lip)
Definition: open.c:63
void GetUsrName(char *, size_t)
Definition: util.c:290

Referenced by FTPLoginHost(), and PostInitPrefs().

◆ FTPInitializeOurHostName()

void FTPInitializeOurHostName ( const  FTPLIPtr)

Definition at line 63 of file open.c.

64{
65 if (lip == NULL)
66 return;
67 if (strcmp(lip->magic, kLibraryMagic))
68 return;
69
70 if (lip->htried == 0) {
71 (void) memset(lip->ourHostName, 0, sizeof(lip->ourHostName));
72 lip->hresult = GetOurHostName(lip->ourHostName, sizeof(lip->ourHostName));
73 }
74 lip->htried++;
75} /* FTPInitializeOurHostName */
int GetOurHostName(char *host, size_t siz)
Definition: ftp.c:81

Referenced by FTPInitializeAnonPassword(), LoadFirewallPrefs(), OpenTrace(), and WriteDefaultFirewallPrefs().

◆ FTPInitIOTimer()

void FTPInitIOTimer ( const  FTPCIPtr)

Definition at line 71 of file io.c.

72{
73 cip->bytesTransferred = (longest_int) 0;
74 cip->expectedSize = kSizeUnknown;
75 cip->mdtm = kModTimeUnknown;
76 cip->rname = NULL;
77 cip->lname = NULL;
78 cip->kBytesPerSec = -1.0;
79 cip->percentCompleted = -1.0;
80 cip->sec = -1.0;
81 cip->secLeft = -1.0;
82 cip->nextProgressUpdate = 0;
83 cip->stalled = 0;
84 cip->dataTimedOut = 0;
85 cip->useProgressMeter = 1;
86 (void) gettimeofday(&cip->t0, NULL);
87} /* FTPInitIOTimer */
#define gettimeofday(tv, tz)
Definition: adns_win32.h:159

Referenced by FTPGetOneF(), and FTPPutOneF().

◆ FTPInitLibrary()

int FTPInitLibrary ( const FTPLIPtr  lip)

Definition at line 1110 of file open.c.

1111{
1112 struct servent *ftp;
1113
1114 if (lip == NULL)
1115 return (kErrBadParameter);
1116
1117 (void) memset(lip, 0, sizeof(FTPLibraryInfo));
1118 if ((ftp = getservbyname("ftp", "tcp")) == NULL)
1119 lip->defaultPort = (unsigned int) kDefaultFTPPort;
1120 else
1121 lip->defaultPort = (unsigned int) ntohs(ftp->s_port);
1122
1123 lip->init = 1;
1125
1126 /* We'll initialize the defaultAnonPassword field
1127 * later when we try the first anon ftp connection.
1128 */
1129
1130#ifdef HAVE_LIBSOCKS
1131 SOCKSinit("libncftp");
1132 lip->socksInit = 1;
1133#endif
1134 return (kNoErr);
1135} /* FTPInitLibrary */
PSERVENT WSAAPI getservbyname(IN const char FAR *name, IN const char FAR *proto)
Definition: getxbyxx.c:500
#define ntohs(x)
Definition: module.h:210
static WCHAR ftp[]
Definition: url.c:29
#define kDefaultFTPPort
Definition: ncftp.h:312
int socksInit
Definition: ncftp.h:116

Referenced by PreInit().

◆ FTPIsDir()

int FTPIsDir ( const FTPCIPtr  cip,
const char *const  dir 
)

Definition at line 1531 of file cmds.c.

1532{
1533 int result, ftype;
1534
1535 if (cip == NULL)
1536 return (kErrBadParameter);
1537 if (strcmp(cip->magic, kLibraryMagic))
1538 return (kErrBadMagic);
1539
1540 if ((dir == NULL) || (dir[0] == '\0')) {
1542 return (kErrInvalidDirParam);
1543 }
1544
1545 result = FTPFileType(cip, dir, &ftype);
1547 result = 0;
1548 if (ftype == 'd')
1549 result = 1;
1550 }
1551 return (result);
1552} /* FTPIsDir */
int FTPFileType(const FTPCIPtr cip, const char *const file, int *const ftype)
Definition: cmds.c:1475

Referenced by FTPFtw(), FTPFtwL2(), and FTPGetFiles3().

◆ FTPIsRegularFile()

int FTPIsRegularFile ( const FTPCIPtr  cip,
const char *const  file 
)

Definition at line 1558 of file cmds.c.

1559{
1560 int result, ftype;
1561
1562 if (cip == NULL)
1563 return (kErrBadParameter);
1564 if (strcmp(cip->magic, kLibraryMagic))
1565 return (kErrBadMagic);
1566
1567 if ((file == NULL) || (file[0] == '\0')) {
1568 cip->errNo = kErrBadParameter;
1569 return (kErrBadParameter);
1570 }
1571
1572 result = FTPFileType(cip, file, &ftype);
1574 result = 1;
1575 if (ftype == 'd')
1576 result = 0;
1577 }
1578 return (result);
1579} /* FTPIsRegularFile */

◆ FTPList()

int FTPList ( const FTPCIPtr  cip,
const int  outfd,
const int  longMode,
const char *const  lsflag 
)

Definition at line 174 of file io.c.

175{
176 const char *cmd;
177 char line[512];
178 char secondaryBuf[768];
179#ifndef NO_SIGNALS
180 char *secBufPtr, *secBufLimit;
181 int nread;
182 volatile int result;
183#else /* NO_SIGNALS */
184 SReadlineInfo lsSrl;
185 int result;
186#endif /* NO_SIGNALS */
187
188 if (cip == NULL)
189 return (kErrBadParameter);
190 if (strcmp(cip->magic, kLibraryMagic))
191 return (kErrBadMagic);
192
193 cmd = (longMode != 0) ? "LIST" : "NLST";
194 if ((lsflag == NULL) || (lsflag[0] == '\0')) {
196 } else {
197 result = FTPStartDataCmd(cip, kNetReading, kTypeAscii, (longest_int) 0, "%s %s", cmd, lsflag);
198 }
199
200
201#ifdef NO_SIGNALS
202
203 if (result == 0) {
204 if (InitSReadlineInfo(&lsSrl, cip->dataSocket, secondaryBuf, sizeof(secondaryBuf), (int) cip->xferTimeout, 1) < 0) {
205 /* Not really fdopen, but close in what we're trying to do. */
207 cip->errNo = kErrFdopenR;
208 Error(cip, kDoPerror, "Could not fdopen.\n");
209 return (result);
210 }
211
212 for (;;) {
213 result = SReadline(&lsSrl, line, sizeof(line) - 2);
214 if (result == kTimeoutErr) {
215 /* timeout */
216 Error(cip, kDontPerror, "Could not directory listing data -- timed out.\n");
217 cip->errNo = kErrDataTimedOut;
218 return (cip->errNo);
219 } else if (result == 0) {
220 /* end of listing -- done */
221 cip->numListings++;
222 break;
223 } else if (result < 0) {
224 /* error */
225 Error(cip, kDoPerror, "Could not read directory listing data");
227 cip->errNo = kErrLISTFailed;
228 break;
229 }
230
231 (void) write(outfd, line, strlen(line));
232 }
233
234 DisposeSReadlineInfo(&lsSrl);
235 if (FTPEndDataCmd(cip, 1) < 0) {
237 cip->errNo = kErrLISTFailed;
238 }
239 } else if (result == kErrGeneric) {
241 cip->errNo = kErrLISTFailed;
242 }
243
244
245#else /* NO_SIGNALS */
246
247 if (result == 0) {
248 /* This line sets the buffer pointer so that the first thing
249 * BufferGets will do is reset and fill the buffer using
250 * real I/O.
251 */
252 secBufPtr = secondaryBuf + sizeof(secondaryBuf);
253 secBufLimit = (char *) 0;
254
255 for (;;) {
256 if (cip->xferTimeout > 0)
257 (void) alarm(cip->xferTimeout);
258 nread = BufferGets(line, sizeof(line), cip->dataSocket, secondaryBuf, &secBufPtr, &secBufLimit, sizeof(secondaryBuf));
259 if (nread <= 0) {
260 if (nread < 0)
261 break;
262 } else {
263 cip->bytesTransferred += (longest_int) nread;
264 (void) STRNCAT(line, "\n");
265 (void) write(outfd, line, strlen(line));
266 }
267 }
268 if (cip->xferTimeout > 0)
269 (void) alarm(0);
270 result = FTPEndDataCmd(cip, 1);
271 if (result < 0) {
273 cip->errNo = kErrLISTFailed;
274 }
275 result = kNoErr;
276 cip->numListings++;
277 } else if (result == kErrGeneric) {
279 cip->errNo = kErrLISTFailed;
280 }
281#endif /* NO_SIGNALS */
282 return (result);
283} /* FTPList */
#define write
Definition: acwin.h:97
#define kDoPerror
Definition: util.h:44
void DisposeSReadlineInfo(SReadlineInfo *)
Definition: SReadline.c:57
int SReadline(SReadlineInfo *, char *const, size_t)
Definition: SReadline.c:76
int InitSReadlineInfo(SReadlineInfo *, int, char *, size_t, int, int)
Definition: SReadline.c:24
#define kTimeoutErr
Definition: sio.h:58
#define kNetReading
Definition: ncftp.h:303
int BufferGets(char *, size_t, int, char *, char **, char **, size_t)
Definition: rcmd.c:978
int FTPEndDataCmd(const FTPCIPtr, int)
Definition: rcmd.c:933
int FTPStartDataCmd(const FTPCIPtr, int, int, longest_int, const char *,...)
Definition: rcmd.c:763
#define kErrLISTFailed
Definition: ncftp_errno.h:47
#define kErrFdopenR
Definition: ncftp_errno.h:25
#define kErrGeneric
Definition: ncftp_errno.h:13
#define kErrDataTimedOut
Definition: ncftp_errno.h:111
longest_int bytesTransferred
Definition: ncftp.h:197
Definition: ftp_var.h:139
Definition: parser.c:49

◆ FTPListToMemory()

int FTPListToMemory ( const FTPCIPtr  cip,
const char *const  pattern,
const LineListPtr  llines,
const char *const  lsflags 
)

Definition at line 2819 of file io.c.

2820{
2821 return (FTPListToMemory2(cip, pattern, llines, lsflags, 1, (int *) 0));
2822} /* FTPListToMemory */

◆ FTPListToMemory2()

int FTPListToMemory2 ( const FTPCIPtr  cip,
const char *const  pattern,
const LineListPtr  llines,
const char *const  lsflags,
const int  blanklines,
int *const  tryMLSD 
)

Definition at line 366 of file io.c.

367{
368 char secondaryBuf[768];
369 char line[512];
370 char lsflags1[128];
371 const char *command = "NLST";
372 const char *scp;
373 char *dcp, *lim;
374#ifndef NO_SIGNALS
375 char *secBufPtr, *secBufLimit;
376 volatile FTPSigProc osigpipe;
377 volatile FTPCIPtr vcip;
378 int sj;
379 int nread;
380 volatile int result;
381#else /* NO_SIGNALS */
382 SReadlineInfo lsSrl;
383 int result;
384#endif /* NO_SIGNALS */
385
386 if (cip == NULL)
387 return (kErrBadParameter);
388 if (strcmp(cip->magic, kLibraryMagic))
389 return (kErrBadMagic);
390
391 if ((llines == NULL) || (pattern == NULL) || (lsflags == NULL))
392 return (kErrBadParameter);
393
394 if ((tryMLSD != (int *) 0) && (*tryMLSD != 0) && (cip->hasMLSD == kCommandAvailable)) {
395 command = "MLSD";
396 if ((lsflags[0] == '-') && (strchr(lsflags, 'd') != NULL) && (cip->hasMLST == kCommandAvailable))
397 command = "MLST";
398 lsflags1[0] = '\0';
400 } else {
401 /* Not using MLSD. */
402 if (tryMLSD != (int *) 0)
403 *tryMLSD = 0;
404 if (lsflags[0] == '-') {
405 /* See if we should use LIST instead. */
406 scp = lsflags + 1;
407 dcp = lsflags1;
408 lim = lsflags1 + sizeof(lsflags1) - 2;
409 for (; *scp != '\0'; scp++) {
410 if (*scp == 'l') {
411 /* do not add the 'l' */
412 command = "LIST";
413 } else if (dcp < lim) {
414 if (dcp == lsflags1)
415 *dcp++ = '-';
416 *dcp++ = *scp;
417 }
418 }
419 *dcp = '\0';
420 } else {
421 (void) STRNCPY(lsflags1, lsflags);
422 }
423 }
424
425 InitLineList(llines);
426
428 cip,
431 (longest_int) 0,
432 "%s%s%s%s%s",
433 command,
434 (lsflags1[0] == '\0') ? "" : " ",
435 lsflags1,
436 (pattern[0] == '\0') ? "" : " ",
437 pattern
438 );
439
440#ifdef NO_SIGNALS
441
442 if (result == 0) {
443 if (InitSReadlineInfo(&lsSrl, cip->dataSocket, secondaryBuf, sizeof(secondaryBuf), (int) cip->xferTimeout, 1) < 0) {
444 /* Not really fdopen, but close in what we're trying to do. */
446 cip->errNo = kErrFdopenR;
447 Error(cip, kDoPerror, "Could not fdopen.\n");
448 return (result);
449 }
450
451 for (;;) {
452 result = SReadline(&lsSrl, line, sizeof(line) - 1);
453 if (result == kTimeoutErr) {
454 /* timeout */
455 Error(cip, kDontPerror, "Could not directory listing data -- timed out.\n");
456 cip->errNo = kErrDataTimedOut;
457 return (cip->errNo);
458 } else if (result == 0) {
459 /* end of listing -- done */
460 cip->numListings++;
461 break;
462 } else if (result < 0) {
463 /* error */
464 Error(cip, kDoPerror, "Could not read directory listing data");
466 cip->errNo = kErrLISTFailed;
467 break;
468 }
469
470 if (line[result - 1] == '\n')
471 line[result - 1] = '\0';
472
473 if ((blankLines == 0) && (result <= 1))
474 continue;
475
476 /* Valid directory listing line of output */
477 if ((line[0] == '.') && ((line[1] == '\0') || ((line[1] == '.') && ((line[2] == '\0') || (iscntrl(line[2]))))))
478 continue; /* Skip . and .. */
479
480 (void) AddLine(llines, line);
481 }
482
483 DisposeSReadlineInfo(&lsSrl);
484 if (FTPEndDataCmd(cip, 1) < 0) {
486 cip->errNo = kErrLISTFailed;
487 }
488 } else if (result == kErrGeneric) {
490 cip->errNo = kErrLISTFailed;
491 }
492
493
494#else /* NO_SIGNALS */
495 vcip = cip;
496 osigpipe = (volatile FTPSigProc) signal(SIGPIPE, BrokenData);
497
498 gGotBrokenData = 0;
499 gCanBrokenDataJmp = 0;
500
501#ifdef HAVE_SIGSETJMP
502 sj = sigsetjmp(gBrokenDataJmp, 1);
503#else
504 sj = setjmp(gBrokenDataJmp);
505#endif /* HAVE_SIGSETJMP */
506
507 if (sj != 0) {
508 (void) signal(SIGPIPE, (FTPSigProc) osigpipe);
509 FTPShutdownHost(vcip);
511 return(vcip->errNo);
512 }
513 gCanBrokenDataJmp = 1;
514
515 if (result == 0) {
516 /* This line sets the buffer pointer so that the first thing
517 * BufferGets will do is reset and fill the buffer using
518 * real I/O.
519 */
520 secBufPtr = secondaryBuf + sizeof(secondaryBuf);
521 secBufLimit = (char *) 0;
522 memset(secondaryBuf, 0, sizeof(secondaryBuf));
523
524 for (;;) {
525 memset(line, 0, sizeof(line));
526 if (cip->xferTimeout > 0)
527 (void) alarm(cip->xferTimeout);
528 nread = BufferGets(line, sizeof(line), cip->dataSocket, secondaryBuf, &secBufPtr, &secBufLimit, sizeof(secondaryBuf));
529 if (nread <= 0) {
530 if (nread < 0)
531 break;
532 if (blankLines != 0)
533 (void) AddLine(llines, line);
534 } else {
535 cip->bytesTransferred += (longest_int) nread;
536
537 if ((line[0] == '.') && ((line[1] == '\0') || ((line[1] == '.') && ((line[2] == '\0') || (iscntrl(line[2]))))))
538 continue; /* Skip . and .. */
539
540 (void) AddLine(llines, line);
541 }
542 }
543 if (cip->xferTimeout > 0)
544 (void) alarm(0);
545 result = FTPEndDataCmd(cip, 1);
546 if (result < 0) {
548 cip->errNo = kErrLISTFailed;
549 }
550 result = kNoErr;
551 cip->numListings++;
552 } else if (result == kErrGeneric) {
554 cip->errNo = kErrLISTFailed;
555 }
556 (void) signal(SIGPIPE, (FTPSigProc) osigpipe);
557#endif /* NO_SIGNALS */
558 return (result);
559} /* FTPListToMemory2 */
#define setjmp
Definition: setjmp.h:209
#define SIGPIPE
Definition: signal.h:35
_Check_return_ _CRTIMP int __cdecl iscntrl(_In_ int _C)
static void FTPRequestMlsOptions(const FTPCIPtr cip)
Definition: io.c:289
static int gGotBrokenData
Definition: io.c:10
int sigsetjmp(sigjmp_buf buf, int savesigs)
void FTPShutdownHost(const FTPCIPtr cip)
Definition: open.c:564
void(* FTPSigProc)(int)
Definition: ncftp.h:76
#define kErrRemoteHostClosedConnection
Definition: ncftp_errno.h:75
int signal
Definition: except.c:82

Referenced by FTPFileExistsNlst(), FTPFileExistsStat(), FTPListToMemory(), FTPRemoteGlob(), FTPRemoteRecursiveFileList(), FTPRemoteRecursiveFileList1(), Ls(), and MlsCmd().

◆ FTPLocalGlob()

int FTPLocalGlob ( FTPCIPtr  cip,
LineListPtr  fileList,
const char pattern,
int  doGlob 
)

Definition at line 1580 of file glob.c.

1581{
1582 string pattern2;
1583 int result;
1584
1585 if (cip == NULL)
1586 return (kErrBadParameter);
1587 if (strcmp(cip->magic, kLibraryMagic))
1588 return (kErrBadMagic);
1589
1590 if (fileList == NULL)
1591 return (kErrBadParameter);
1592 InitLineList(fileList);
1593
1594 if ((pattern == NULL) || (pattern[0] == '\0'))
1595 return (kErrBadParameter);
1596
1597 (void) STRNCPY(pattern2, pattern); /* Don't nuke the original. */
1598
1599 /* Pre-process for ~'s. */
1600 ExpandTilde(pattern2, sizeof(pattern2));
1601 InitLineList(fileList);
1602 result = kNoErr;
1603
1604 if ((doGlob == 1) && (GLOBCHARSINSTR(pattern2))) {
1605#if defined(WIN32) || defined(_WINDOWS)
1606 result = WinLocalGlob(cip, fileList, pattern2);
1607#else
1608 result = LazyUnixLocalGlob(cip, fileList, pattern2);
1609#endif
1610 } else {
1611 /* Or, if there were no globbing characters in 'pattern', then
1612 * the pattern is really just a single pathname.
1613 */
1614 (void) AddLine(fileList, pattern2);
1615 }
1616
1617 return (result);
1618} /* FTPLocalGlob */
static int LazyUnixLocalGlob(FTPCIPtr cip, LineListPtr fileList, const char *const pattern)
Definition: glob.c:1539
static void ExpandTilde(char *pattern, size_t siz)
Definition: glob.c:1429
#define GLOBCHARSINSTR(a)
Definition: ncftp.h:358

Referenced by EchoCmd(), FTPPutFiles3(), LocalRmCmd(), LocalRmdirCmd(), and SpoolPutCmd().

◆ FTPLocalRecursiveFileList()

int FTPLocalRecursiveFileList ( FTPCIPtr  cip,
LineListPtr  fileList,
FileInfoListPtr  files 
)

Definition at line 1333 of file glob.c.

1334{
1335 return (FTPLocalRecursiveFileList2(cip, fileList, files, 0));
1336} /* FTPLocalRecursiveFileList */
int FTPLocalRecursiveFileList2(FTPCIPtr cip, LineListPtr fileList, FileInfoListPtr files, int erelative)
Definition: glob.c:1276

Referenced by FTPPutFiles3().

◆ FTPLocalRecursiveFileList2()

int FTPLocalRecursiveFileList2 ( FTPCIPtr  cip,
LineListPtr  fileList,
FileInfoListPtr  files,
int  erelative 
)

Definition at line 1276 of file glob.c.

1277{
1278 LinePtr filePtr, nextFilePtr;
1279#if defined(WIN32) || defined(_WINDOWS)
1280 char fullpath[_MAX_PATH + 1];
1281 char relpath[_MAX_PATH + 1];
1282#else
1283 char fullpath[512];
1284 char relpath[512];
1285#endif
1286 struct Stat st;
1287 FileInfo fi;
1288 char *cp;
1289
1290 InitFileInfoList(files);
1291
1292 for (filePtr = fileList->first;
1293 filePtr != NULL;
1294 filePtr = nextFilePtr)
1295 {
1296 nextFilePtr = filePtr->next;
1297
1298 (void) STRNCPY(fullpath, filePtr->line); /* initialize fullpath */
1299 if ((erelative != 0) || (strcmp(filePtr->line, ".") == 0) || (filePtr->line[0] == '\0'))
1300 (void) STRNCPY(relpath, "");
1301 else if ((cp = StrRFindLocalPathDelim(filePtr->line)) == NULL)
1302 (void) STRNCPY(relpath, filePtr->line);
1303 else
1304 (void) STRNCPY(relpath, cp + 1);
1305 if (Lstat(fullpath, &st) < 0) {
1306 Error(cip, kDoPerror, "could not stat %s.\n", fullpath);
1307 continue;
1308 }
1309
1310 if (S_ISDIR(st.st_mode) == 0) {
1311 fi.relname = StrDup(relpath);
1312 fi.rname = NULL;
1313 fi.lname = StrDup(fullpath);
1314 fi.mdtm = st.st_mtime;
1315 fi.size = (longest_int) st.st_size;
1316 fi.rlinkto = NULL;
1317 fi.plug = NULL;
1318 fi.type = '-';
1319 (void) AddFileInfo(files, &fi);
1320 continue; /* wasn't a directory */
1321 }
1322
1323 /* Paths collected must be relative. */
1324 Traverse(cip, fullpath, &st, relpath, files);
1325 }
1326 return (kNoErr);
1327} /* FTPLocalRecursiveFileList */
#define S_ISDIR(mode)
Definition: various.h:18
static void Traverse(FTPCIPtr cip, char *fullpath, struct Stat *st, char *relpath, FileInfoListPtr filp)
Definition: glob.c:1184
#define Lstat
Definition: syshdrs.h:80
#define Stat
Definition: syshdrs.h:78
void InitFileInfoList(FileInfoListPtr list)
Definition: linelist.c:193
#define _MAX_PATH
Definition: utility.h:77
#define StrRFindLocalPathDelim(a)
Definition: ncftp.h:495

Referenced by FTPLocalRecursiveFileList().

◆ FTPLoginHost()

int FTPLoginHost ( const FTPCIPtr  cip)

Definition at line 110 of file open.c.

111{
112 ResponsePtr rp;
114 int anonLogin;
115 int sentpass = 0;
116 int fwloggedin;
117 int firstTime;
118 char cwd[512];
119
120 if (cip == NULL)
121 return (kErrBadParameter);
123 return (kErrBadParameter);
124
125 if (strcmp(cip->magic, kLibraryMagic))
126 return (kErrBadMagic);
127
128 anonLogin = 0;
129 if (cip->user[0] == '\0')
130 (void) STRNCPY(cip->user, "anonymous");
131 if ((strcmp(cip->user, "anonymous") == 0) || (strcmp(cip->user, "ftp") == 0)) {
132 anonLogin = 1;
133 /* Try to get the email address if you didn't specify
134 * a password when the user is anonymous.
135 */
136 if (cip->pass[0] == '\0') {
138 (void) STRNCPY(cip->pass, cip->lip->defaultAnonPassword);
139 }
140 }
141
142 rp = InitResponse();
143 if (rp == NULL) {
145 cip->errNo = kErrMallocFailed;
146 goto done2;
147 }
148
149 for (firstTime = 1, fwloggedin = 0; ; ) {
150 /* Here's a mini finite-automaton for the login process.
151 *
152 * Originally, the FTP protocol was designed to be entirely
153 * implementable from a FA. It could be done, but I don't think
154 * it's something an interactive process could be the most
155 * effective with.
156 */
157
158 if (firstTime != 0) {
159 rp->code = 220;
160 firstTime = 0;
161 } else if (result < 0) {
162 goto done;
163 }
164
165 switch (rp->code) {
166 case 220: /* Welcome, ready for new user. */
167 if ((cip->firewallType == kFirewallNotInUse) || (fwloggedin != 0)) {
168 ReInitResponse(cip, rp);
169 result = RCmd(cip, rp, "USER %s", cip->user);
170 } else if (cip->firewallType == kFirewallUserAtSite) {
171 ReInitResponse(cip, rp);
172 result = RCmd(cip, rp, "USER %s@%s", cip->user, cip->host);
173 } else if (cip->firewallType == kFirewallUserAtUserPassAtPass) {
174 ReInitResponse(cip, rp);
175 result = RCmd(cip, rp, "USER %s@%s@%s", cip->user, cip->firewallUser, cip->host);
176 } else if (cip->firewallType == kFirewallUserAtSiteFwuPassFwp) {
177 ReInitResponse(cip, rp);
178 result = RCmd(cip, rp, "USER %s@%s %s", cip->user, cip->host, cip->firewallUser);
179 } else if (cip->firewallType == kFirewallFwuAtSiteFwpUserPass) {
180 /* only reached when !fwloggedin */
181 ReInitResponse(cip, rp);
182 result = RCmd(cip, rp, "USER %s@%s", cip->firewallUser, cip->host);
183 } else if (cip->firewallType > kFirewallNotInUse) {
184 ReInitResponse(cip, rp);
185 result = RCmd(cip, rp, "USER %s", cip->firewallUser);
186 } else {
187 goto unknown;
188 }
189 break;
190
191 case 230: /* 230 User logged in, proceed. */
192 case 231: /* User name accepted. */
193 case 202: /* Command not implemented, superfluous at this site. */
194 if ((cip->firewallType == kFirewallNotInUse) || (fwloggedin != 0))
195 goto okay;
196
197 /* Now logged in to the firewall. */
198 fwloggedin++;
199
201 ReInitResponse(cip, rp);
202 result = RCmd(cip, rp, "USER %s@%s", cip->user, cip->host);
203 } else if (cip->firewallType == kFirewallUserAtUserPassAtPass) {
204 goto okay;
205 } else if (cip->firewallType == kFirewallOpenSite) {
206 ReInitResponse(cip, rp);
207 result = RCmd(cip, rp, "OPEN %s", cip->host);
208 } else if (cip->firewallType == kFirewallSiteSite) {
209 ReInitResponse(cip, rp);
210 result = RCmd(cip, rp, "SITE %s", cip->host);
211 } else if (cip->firewallType == kFirewallFwuAtSiteFwpUserPass) {
212 /* only reached when !fwloggedin */
213 ReInitResponse(cip, rp);
214 result = RCmd(cip, rp, "USER %s", cip->user);
215 } else /* kFirewallUserAtSite */ {
216 goto okay;
217 }
218 break;
219
220 case 421: /* 421 Service not available, closing control connection. */
222 goto done;
223
224 case 331: /* 331 User name okay, need password. */
225 if ((cip->firewallType == kFirewallNotInUse) || (fwloggedin != 0)) {
226 if ((cip->pass[0] == '\0') && (cip->passphraseProc != NoGetPassphraseProc))
227 (*cip->passphraseProc)(cip, &rp->msg, cip->pass, sizeof(cip->pass));
228 ReInitResponse(cip, rp);
229 result = RCmd(cip, rp, "PASS %s", cip->pass);
230 } else if (cip->firewallType == kFirewallUserAtSite) {
231 ReInitResponse(cip, rp);
232 result = RCmd(cip, rp, "PASS %s", cip->pass);
233 } else if (cip->firewallType == kFirewallUserAtUserPassAtPass) {
234 ReInitResponse(cip, rp);
235 result = RCmd(cip, rp, "PASS %s@%s", cip->pass, cip->firewallPass);
236 } else if (cip->firewallType == kFirewallUserAtSiteFwuPassFwp) {
237 ReInitResponse(cip, rp);
238 result = RCmd(cip, rp, "PASS %s", cip->pass);
239 } else if (cip->firewallType == kFirewallFwuAtSiteFwpUserPass) {
240 /* only reached when !fwloggedin */
241 ReInitResponse(cip, rp);
242 result = RCmd(cip, rp, "PASS %s", cip->firewallPass);
243 } else if (cip->firewallType > kFirewallNotInUse) {
244 ReInitResponse(cip, rp);
245 result = RCmd(cip, rp, "PASS %s", cip->firewallPass);
246 } else {
247 goto unknown;
248 }
249 sentpass++;
250 break;
251
252 case 332: /* 332 Need account for login. */
253 case 532: /* 532 Need account for storing files. */
254 if ((cip->firewallType == kFirewallNotInUse) || (fwloggedin != 0)) {
255 ReInitResponse(cip, rp);
256 result = RCmd(cip, rp, "ACCT %s", cip->acct);
257 } else if (cip->firewallType == kFirewallUserAtSiteFwuPassFwp) {
258 ReInitResponse(cip, rp);
259 result = RCmd(cip, rp, "ACCT %s", cip->firewallPass);
260 } else {
261 /* ACCT not supported on firewall. */
262 goto unknown;
263 }
264 break;
265
266 case 530: /* Not logged in. */
268 goto done;
269
270 case 501: /* Syntax error in parameters or arguments. */
271 case 503: /* Bad sequence of commands. */
272 case 550: /* Can't set guest privileges. */
273 goto done;
274
275 default:
276 unknown:
277 if (rp->msg.first == NULL) {
278 Error(cip, kDontPerror, "Lost connection during login.\n");
279 } else {
280 Error(cip, kDontPerror, "Unexpected response: %s\n",
281 rp->msg.first->line
282 );
283 }
284 goto done;
285 }
286 }
287
288okay:
289 /* Do the application's connect message callback, if present. */
290 if (cip->onLoginMsgProc != 0)
291 (*cip->onLoginMsgProc)(cip, rp);
292 DoneWithResponse(cip, rp);
293 result = 0;
294 cip->loggedIn = 1;
295
296 /* Make a note of what our root directory is.
297 * This is often different from "/" when not
298 * logged in anonymously.
299 */
300 if (cip->startingWorkingDirectory != NULL) {
303 }
304 if ((cip->doNotGetStartingWorkingDirectory == 0) &&
305 (FTPGetCWD(cip, cwd, sizeof(cwd)) == kNoErr))
306 {
308 }
309
310 /* When a new site is opened, ASCII mode is assumed (by protocol). */
311 cip->curTransferType = 'A';
312 PrintF(cip, "Logged in to %s as %s.\n", cip->host, cip->user);
313
314 /* Don't leave cleartext password in memory. */
315 if ((anonLogin == 0) && (cip->leavePass == 0))
316 (void) memset(cip->pass, '*', strlen(cip->pass));
317
318 if (result < 0)
319 cip->errNo = result;
320 return result;
321
322done:
323 DoneWithResponse(cip, rp);
324
325done2:
326 /* Don't leave cleartext password in memory. */
327 if ((anonLogin == 0) && (cip->leavePass == 0))
328 (void) memset(cip->pass, '*', strlen(cip->pass));
329 if (result < 0)
330 cip->errNo = result;
331 return result;
332} /* FTPLoginHost */
static WCHAR unknown[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1605
void FTPInitializeAnonPassword(const FTPLIPtr lip)
Definition: open.c:81
#define kFirewallUserAtSite
Definition: ncftp.h:389
#define kFirewallLoginThenUserAtSite
Definition: ncftp.h:390
#define kFirewallSiteSite
Definition: ncftp.h:391
#define kFirewallUserAtUserPassAtPass
Definition: ncftp.h:393
void ReInitResponse(const FTPCIPtr, ResponsePtr)
Definition: rcmd.c:142
#define kFirewallFwuAtSiteFwpUserPass
Definition: ncftp.h:394
#define kFirewallUserAtSiteFwuPassFwp
Definition: ncftp.h:395
#define kFirewallOpenSite
Definition: ncftp.h:392
#define kFirewallLastType
Definition: ncftp.h:396
#define NoGetPassphraseProc
Definition: ncftp.h:453
#define kErrLoginFailed
Definition: ncftp_errno.h:73
#define kErrBadRemoteUser
Definition: ncftp_errno.h:71
#define kErrHostDisconnectedDuringLogin
Definition: ncftp_errno.h:70
#define kErrBadRemoteUserOrPassword
Definition: ncftp_errno.h:72
int curTransferType
Definition: ncftp.h:157
int doNotGetStartingWorkingDirectory
Definition: ncftp.h:237
char firewallPass[64]
Definition: ncftp.h:219
FTPGetPassphraseProc passphraseProc
Definition: ncftp.h:242
FTPLoginMessageProc onLoginMsgProc
Definition: ncftp.h:227
char firewallUser[64]
Definition: ncftp.h:218
char acct[64]
Definition: ncftp.h:139
char defaultAnonPassword[80]
Definition: ncftp.h:121

Referenced by FTPOpenHost().

◆ FTPMkdir()

int FTPMkdir ( const FTPCIPtr  cip,
const char *const  newDir,
const int  recurse 
)

Definition at line 641 of file cmds.c.

642{
643 return (FTPMkdir2(cip, newDir, recurse, NULL));
644} /* FTPMkdir */
int FTPMkdir2(const FTPCIPtr cip, const char *const newDir, const int recurse, const char *const curDir)
Definition: cmds.c:472

Referenced by FTPChdir3(), FTPPutFiles3(), and MkdirCmd().

◆ FTPMkdir2()

int FTPMkdir2 ( const FTPCIPtr  cip,
const char *const  newDir,
const int  recurse,
const char *const  curDir 
)

Definition at line 472 of file cmds.c.

473{
474 int result, result2;
475 char *cp, *newTreeStart, *cp2;
476 char dir[512];
477 char dir2[512];
478 char c;
479
480 if (cip == NULL)
481 return (kErrBadParameter);
482 if (strcmp(cip->magic, kLibraryMagic))
483 return (kErrBadMagic);
484
485 if ((newDir == NULL) || (newDir[0] == '\0')) {
487 return (kErrInvalidDirParam);
488 }
489
490 /* Preserve old working directory. */
491 if ((curDir == NULL) || (curDir[0] == '\0')) {
492 /* This hack is nice so you can eliminate an
493 * unnecessary "PWD" command on the server,
494 * since if you already knew what directory
495 * you're in. We want to minimize the number
496 * of client-server exchanges when feasible.
497 */
498 (void) FTPGetCWD(cip, cip->buf, cip->bufSize);
499 }
500
501 result = FTPChdir(cip, newDir);
502 if (result == kNoErr) {
503 /* Directory already exists -- but we
504 * must now change back to where we were.
505 */
506 result2 = FTPChdir(cip, ((curDir == NULL) || (curDir[0] == '\0')) ? cip->buf : curDir);
507 if (result2 < 0) {
510 return (result);
511 }
512
513 /* Don't need to create it. */
514 return (kNoErr);
515 }
516
517 if (recurse == kRecursiveNo) {
518 result = FTPCmd(cip, "MKD %s", newDir);
519 if (result > 0) {
520 if (result != 2) {
521 Error(cip, kDontPerror, "MKD %s failed; [%s]\n", newDir, cip->lastFTPCmdResultStr);
523 cip->errNo = kErrMKDFailed;
524 return (result);
525 } else {
526 result = kNoErr;
527 }
528 }
529 } else {
530 (void) STRNCPY(dir, newDir);
531
532 /* Strip trailing slashes. */
533 cp = dir + strlen(dir) - 1;
534 for (;;) {
535 if (cp <= dir) {
536 if ((newDir == NULL) || (newDir[0] == '\0')) {
539 return (result);
540 }
541 }
542 if ((*cp != '/') && (*cp != '\\')) {
543 cp[1] = '\0';
544 break;
545 }
546 --cp;
547 }
548 (void) STRNCPY(dir2, dir);
549
550 if ((strrchr(dir, '/') == dir) || (strrchr(dir, '\\') == dir)) {
551 /* Special case "mkdir /subdir" */
552 result = FTPCmd(cip, "MKD %s", dir);
553 if (result < 0) {
554 return (result);
555 }
556 if (result != 2) {
557 Error(cip, kDontPerror, "MKD %s failed; [%s]\n", dir, cip->lastFTPCmdResultStr);
559 cip->errNo = kErrMKDFailed;
560 return (result);
561 }
562 /* Haven't chdir'ed, don't need to goto goback. */
563 return (kNoErr);
564 }
565
566 for (;;) {
567 cp = strrchr(dir, '/');
568 if (cp == NULL)
569 cp = strrchr(dir, '\\');
570 if (cp == NULL) {
571 cp = dir + strlen(dir) - 1;
572 if (dir[0] == '\0') {
574 cip->errNo = kErrMKDFailed;
575 return (result);
576 }
577 /* Note: below we will refer to cp + 1
578 * which is why we set cp to point to
579 * the byte before the array begins!
580 */
581 cp = dir - 1;
582 break;
583 }
584 if (cp == dir) {
586 cip->errNo = kErrMKDFailed;
587 return (result);
588 }
589 *cp = '\0';
590 result = FTPChdir(cip, dir);
591 if (result == 0) {
592 break; /* Found a valid parent dir. */
593 /* from this point, we need to preserve old dir. */
594 }
595 }
596
597 newTreeStart = dir2 + ((cp + 1) - dir);
598 for (cp = newTreeStart; ; ) {
599 cp2 = cp;
600 cp = strchr(cp2, '/');
601 c = '/';
602 if (cp == NULL)
603 cp = strchr(cp2, '\\');
604 if (cp != NULL) {
605 c = *cp;
606 *cp = '\0';
607 if (cp[1] == '\0') {
608 /* Done, if they did "mkdir /tmp/dir/" */
609 break;
610 }
611 }
612 result = FTPCmd(cip, "MKD %s", newTreeStart);
613 if (result < 0) {
614 return (result);
615 }
616 if (result != 2) {
617 Error(cip, kDontPerror, "Cwd=%s; MKD %s failed; [%s]\n", cip->buf, newTreeStart, cip->lastFTPCmdResultStr);
619 cip->errNo = kErrMKDFailed;
620 goto goback;
621 }
622 if (cp == NULL)
623 break; /* No more to make, done. */
624 *cp++ = c;
625 }
626 result = kNoErr;
627
628goback:
629 result2 = FTPChdir(cip, ((curDir == NULL) || (curDir[0] == '\0')) ? cip->buf : curDir);
630 if ((result == 0) && (result2 < 0)) {
633 }
634 }
635 return (result);
636} /* FTPMkdir2 */
#define kRecursiveNo
Definition: ncftp.h:363
#define kErrMKDFailed
Definition: ncftp_errno.h:57
char lastFTPCmdResultStr[128]
Definition: ncftp.h:214

Referenced by FTPMkdir().

◆ FTPMListOneFile()

int FTPMListOneFile ( const FTPCIPtr  cip,
const char *const  file,
const MLstItemPtr  mlip 
)

Definition at line 947 of file cmds.c.

948{
949 int result;
950 ResponsePtr rp;
951
952 /* We do a special check for older versions of NcFTPd which
953 * are based off of an incompatible previous version of IETF
954 * extensions.
955 *
956 * Roxen also seems to be way outdated, where MLST was on the
957 * data connection among other things.
958 *
959 */
960 if (
961 (cip->hasMLST == kCommandNotAvailable) ||
962 ((cip->serverType == kServerTypeNcFTPd) && (cip->ietfCompatLevel < 19981201)) ||
964 ) {
966 return (cip->errNo);
967 }
968
969 rp = InitResponse();
970 if (rp == NULL) {
972 Error(cip, kDontPerror, "Malloc failed.\n");
973 } else {
974 result = RCmd(cip, rp, "MLST %s", file);
975 if (
976 (result == 2) &&
977 (rp->msg.first->line != NULL) &&
978 (rp->msg.first->next != NULL) &&
979 (rp->msg.first->next->line != NULL)
980 ) {
981 result = UnMlsT(rp->msg.first->next->line, mlip);
982 if (result < 0) {
984 }
985 } else if (UNIMPLEMENTED_CMD(rp->code)) {
989 } else {
990 cip->errNo = kErrMLSTFailed;
992 }
993 DoneWithResponse(cip, rp);
994 }
995
996 return (result);
997} /* FTPMListOneFile */
int UnMlsT(const char *const line0, const MLstItemPtr mlip)
Definition: glob.c:693
#define kServerTypeNcFTPd
Definition: ncftp.h:463
#define kServerTypeRoxen
Definition: ncftp.h:471
#define kErrMLSTNotAvailable
Definition: ncftp_errno.h:99
#define kErrInvalidMLSTResponse
Definition: ncftp_errno.h:98
int ietfCompatLevel
Definition: ncftp.h:233

Referenced by FTPFileExists2(), FTPFileSizeAndModificationTime(), and FTPFileType().

◆ FTPOpenHost()

int FTPOpenHost ( const FTPCIPtr  cip)

Definition at line 818 of file open.c.

819{
820 int result;
821 time_t t0, t1;
822 int elapsed;
823 int dials;
824
825 if (cip == NULL)
826 return (kErrBadParameter);
827 if (strcmp(cip->magic, kLibraryMagic))
828 return (kErrBadMagic);
829
830 if (cip->host[0] == '\0') {
831 cip->errNo = kErrBadParameter;
832 return (kErrBadParameter);
833 }
834
835 for ( result = kErrConnectMiscErr, dials = 0;
836 cip->maxDials < 0 || dials < cip->maxDials;
837 dials++)
838 {
839 /* Allocate (or if the host was closed, reallocate)
840 * the transfer data buffer.
841 */
842 result = FTPAllocateHost(cip);
843 if (result < 0)
844 return (result);
845
846 if (dials > 0)
847 PrintF(cip, "Retry Number: %d\n", dials);
848 if (cip->redialStatusProc != 0)
849 (*cip->redialStatusProc)(cip, kRedialStatusDialing, dials);
850 (void) time(&t0);
851 result = OpenControlConnection(cip, cip->host, cip->port);
852 (void) time(&t1);
853 if (result == kNoErr) {
854 /* We were hooked up successfully. */
855 PrintF(cip, "Connected to %s.\n", cip->host);
856
857 result = FTPLoginHost(cip);
858 if (result == kNoErr) {
859 (void) FTPQueryFeatures(cip);
860 break;
861 }
862
863 /* Close and try again. */
864 (void) FTPCloseHost(cip);
865
866 /* Originally we also stopped retyring if
867 * we got kErrBadRemoteUser and non-anonymous,
868 * but some FTP servers apparently do their
869 * max user check after the username is sent.
870 */
871 if (result == kErrBadRemoteUserOrPassword /* || (result == kErrBadRemoteUser) */) {
872 if (strcmp(cip->user, "anonymous") != 0) {
873 /* Non-anonymous login was denied, and
874 * retrying is not going to help.
875 */
876 break;
877 }
878 }
880 /* Irrecoverable error, so don't bother redialing.
881 * The error message should have already been printed
882 * from OpenControlConnection().
883 */
884 PrintF(cip, "Cannot recover from miscellaneous open error %d.\n", result);
885 return result;
886 }
887
888 /* Retryable error, wait and then redial. */
889 if (cip->redialDelay > 0) {
890 /* But don't sleep if this is the last loop. */
891 if ((cip->maxDials < 0) || (dials < (cip->maxDials - 1))) {
892 elapsed = (int) (t1 - t0);
893 if (elapsed < cip->redialDelay) {
894 PrintF(cip, "Sleeping %u seconds.\n",
895 (unsigned) cip->redialDelay - elapsed);
896 if (cip->redialStatusProc != 0)
897 (*cip->redialStatusProc)(cip, kRedialStatusSleeping, cip->redialDelay - elapsed);
898 (void) sleep((unsigned) cip->redialDelay - elapsed);
899 }
900 }
901 }
902 }
903 return (result);
904} /* FTPOpenHost */
#define sleep
Definition: syshdrs.h:37
__u16 time
Definition: mkdosfs.c:8
int OpenControlConnection(const FTPCIPtr cip, char *host, unsigned int port)
Definition: ftp.c:347
int FTPQueryFeatures(const FTPCIPtr cip)
Definition: open.c:380
int FTPCloseHost(const FTPCIPtr cip)
Definition: open.c:523
static int FTPAllocateHost(const FTPCIPtr cip)
Definition: open.c:39
int FTPLoginHost(const FTPCIPtr cip)
Definition: open.c:110
#define kRedialStatusDialing
Definition: ncftp.h:346
#define kRedialStatusSleeping
Definition: ncftp.h:347
#define kErrConnectRetryableErr
Definition: ncftp_errno.h:36
#define kErrConnectMiscErr
Definition: ncftp_errno.h:35
#define kErrConnectRefused
Definition: ncftp_errno.h:37
FTPRedialStatusProc redialStatusProc
Definition: ncftp.h:225

Referenced by DoOpen().

◆ FTPOpenHostNoLogin()

int FTPOpenHostNoLogin ( const FTPCIPtr  cip)

Definition at line 910 of file open.c.

911{
912 int result;
913 time_t t0, t1;
914 int elapsed;
915 int dials;
916
917 if (cip == NULL)
918 return (kErrBadParameter);
919 if (strcmp(cip->magic, kLibraryMagic))
920 return (kErrBadMagic);
921
922 if (cip->host[0] == '\0') {
923 cip->errNo = kErrBadParameter;
924 return (kErrBadParameter);
925 }
926
927 for ( result = kErrConnectMiscErr, dials = 0;
928 cip->maxDials < 0 || dials < cip->maxDials;
929 dials++)
930 {
931
932 /* Allocate (or if the host was closed, reallocate)
933 * the transfer data buffer.
934 */
935 result = FTPAllocateHost(cip);
936 if (result < 0)
937 return (result);
938
939 if (dials > 0)
940 PrintF(cip, "Retry Number: %d\n", dials);
941 if (cip->redialStatusProc != 0)
942 (*cip->redialStatusProc)(cip, kRedialStatusDialing, dials);
943 (void) time(&t0);
944 result = OpenControlConnection(cip, cip->host, cip->port);
945 (void) time(&t1);
946 if (result == kNoErr) {
947 /* We were hooked up successfully. */
948 PrintF(cip, "Connected to %s.\n", cip->host);
949
950 /* Not logging in... */
951 if (result == kNoErr)
952 break;
954 /* Irrecoverable error, so don't bother redialing.
955 * The error message should have already been printed
956 * from OpenControlConnection().
957 */
958 PrintF(cip, "Cannot recover from miscellaneous open error %d.\n", result);
959 return result;
960 }
961
962 /* Retryable error, wait and then redial. */
963 if (cip->redialDelay > 0) {
964 /* But don't sleep if this is the last loop. */
965 if ((cip->maxDials < 0) || (dials < (cip->maxDials - 1))) {
966 elapsed = (int) (t1 - t0);
967 if (elapsed < cip->redialDelay) {
968 PrintF(cip, "Sleeping %u seconds.\n",
969 (unsigned) cip->redialDelay - elapsed);
970 if (cip->redialStatusProc != 0)
971 (*cip->redialStatusProc)(cip, kRedialStatusSleeping, cip->redialDelay - elapsed);
972 (void) sleep((unsigned) cip->redialDelay - elapsed);
973 }
974 }
975 }
976 }
977 return (result);
978} /* FTPOpenHostNoLogin */

◆ FTPPerror()

void FTPPerror ( const FTPCIPtr  cip,
const int  err,
const int  eerr,
const char *const  s1,
const char *const  s2 
)

Definition at line 134 of file errno.c.

135{
136 if (err != kNoErr) {
137 if (err == eerr) {
138 if ((s2 == NULL) || (s2[0] == '\0')) {
139 if ((s1 == NULL) || (s1[0] == '\0')) {
140 (void) fprintf(stderr, "server said: %s\n", cip->lastFTPCmdResultStr);
141 } else {
142 (void) fprintf(stderr, "%s: server said: %s\n", s1, cip->lastFTPCmdResultStr);
143 }
144 } else if ((s1 == NULL) || (s1[0] == '\0')) {
145 (void) fprintf(stderr, "%s: server said: %s\n", s2, cip->lastFTPCmdResultStr);
146 } else {
147 (void) fprintf(stderr, "%s %s: server said: %s\n", s1, s2, cip->lastFTPCmdResultStr);
148 }
149 } else {
150 if ((s2 == NULL) || (s2[0] == '\0')) {
151 if ((s1 == NULL) || (s1[0] == '\0')) {
152 (void) fprintf(stderr, "%s.\n", FTPStrError(cip->errNo));
153 } else {
154 (void) fprintf(stderr, "%s: %s.\n", s1, FTPStrError(cip->errNo));
155 }
156 } else if ((s1 == NULL) || (s1[0] == '\0')) {
157 (void) fprintf(stderr, "%s: %s.\n", s2, FTPStrError(cip->errNo));
158 } else {
159 (void) fprintf(stderr, "%s %s: %s.\n", s1, s2, FTPStrError(cip->errNo));
160 }
161 }
162 }
163} /* FTPPerror */
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
struct S1 s1
struct S2 s2
const char * FTPStrError(int e)
Definition: errno.c:114

Referenced by CatCmd(), ChdirCmd(), ChmodCmd(), DeleteCmd(), DoOpen(), EchoCmd(), GetCmd(), LocalRmCmd(), LocalRmdirCmd(), MkdirCmd(), MlsCmd(), OpenCmd(), OpenURL(), PageCmd(), PutCmd(), PwdCmd(), RenameCmd(), RGlobCmd(), RmdirCmd(), RmtHelpCmd(), SpoolGetCmd(), SpoolPutCmd(), SymlinkCmd(), TypeCmd(), and UmaskCmd().

◆ FTPPutFiles()

int FTPPutFiles ( const FTPCIPtr  cip,
const char *const  pattern,
const char *const  dstdir,
const int  recurse,
const int  doGlob 
)

Definition at line 2784 of file io.c.

2785{
2786 return (FTPPutFiles3(cip, pattern, dstdir, recurse, doGlob, kTypeBinary, 0, NULL, NULL, kResumeNo, kDeleteNo, NoConfirmResumeUploadProc, 0));
2787} /* FTPPutFiles */
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 ConfirmResumeUploadProc resumeProc, int UNUSED(reserved))
Definition: io.c:1298
#define NoConfirmResumeUploadProc
Definition: ncftp.h:452

◆ FTPPutFiles2()

int FTPPutFiles2 ( const FTPCIPtr  cip,
const char *const  pattern,
const char *const  dstdir,
const int  recurse,
const int  doGlob,
const int  xtype,
const int  appendflag,
const char *const  tmppfx,
const char *const  tmpsfx 
)

Definition at line 2793 of file io.c.

2794{
2795 return (FTPPutFiles3(cip, pattern, dstdir, recurse, doGlob, xtype, appendflag, tmppfx, tmpsfx, kResumeNo, kDeleteNo, NoConfirmResumeUploadProc, 0));
2796} /* FTPPutFiles2 */

◆ FTPPutFiles3()

int FTPPutFiles3 ( const FTPCIPtr  cip,
const char *const  pattern,
const char *const  dstdir,
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 ConfirmResumeUploadProc  resumeProc,
int  reserved 
)

◆ FTPPutFilesAscii()

int FTPPutFilesAscii ( const FTPCIPtr  cip,
const char *const  pattern,
const char *const  dstdir,
const int  recurse,
const int  doGlob 
)

Definition at line 2811 of file io.c.

2812{
2813 return (FTPPutFiles3(cip, pattern, dstdir, recurse, doGlob, kTypeAscii, 0, NULL, NULL, kResumeNo, kDeleteNo, NoConfirmResumeUploadProc, 0));
2814} /* FTPPutFilesAscii */

◆ FTPPutOneFile()

int FTPPutOneFile ( const FTPCIPtr  cip,
const char *const  file,
const char *const  dstfile 
)

Definition at line 2766 of file io.c.

2767{
2768 return (FTPPutOneFile3(cip, file, dstfile, kTypeBinary, -1, 0, NULL, NULL, kResumeNo, kDeleteNo, NoConfirmResumeUploadProc, 0));
2769} /* FTPPutOneFile */
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 ConfirmResumeUploadProc resumeProc, int UNUSED(reserved))
Definition: io.c:1262

◆ FTPPutOneFile2()

int FTPPutOneFile2 ( 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 
)

Definition at line 2775 of file io.c.

2776{
2777 return (FTPPutOneFile3(cip, file, dstfile, xtype, fdtouse, appendflag, tmppfx, tmpsfx, kResumeNo, kDeleteNo, NoConfirmResumeUploadProc, 0));
2778} /* FTPPutOneFile2 */

◆ FTPPutOneFile3()

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 ConfirmResumeUploadProc  resumeProc,
int  reserved 
)

◆ FTPPutOneFileAscii()

int FTPPutOneFileAscii ( const FTPCIPtr  cip,
const char *const  file,
const char *const  dstfile 
)

Definition at line 2802 of file io.c.

2803{
2804 return (FTPPutOneFile3(cip, file, dstfile, kTypeAscii, -1, 0, NULL, NULL, kResumeNo, kDeleteNo, NoConfirmResumeUploadProc, 0));
2805} /* FTPPutOneFileAscii */

◆ FTPQueryFeatures()

int FTPQueryFeatures ( const  FTPCIPtr)

Definition at line 380 of file open.c.

381{
382 ResponsePtr rp;
383 int result;
384 LinePtr lp;
385 char *cp, *p;
386
387 if (cip == NULL)
388 return (kErrBadParameter);
389 if (strcmp(cip->magic, kLibraryMagic))
390 return (kErrBadMagic);
391
392 if (cip->serverType == kServerTypeNetWareFTP) {
393 /* NetWare 5.00 server freaks out when
394 * you give it a command it doesn't
395 * recognize, so cheat here and return.
396 */
397 cip->hasPASV = kCommandAvailable;
398 cip->hasSIZE = kCommandNotAvailable;
399 cip->hasMDTM = kCommandNotAvailable;
400 cip->hasREST = kCommandNotAvailable;
401 cip->NLSTfileParamWorks = kCommandAvailable;
402 cip->hasUTIME = kCommandNotAvailable;
403 cip->hasCLNT = kCommandNotAvailable;
404 cip->hasMLST = kCommandNotAvailable;
405 cip->hasMLSD = kCommandNotAvailable;
406 return (kNoErr);
407 }
408
409 rp = InitResponse();
410 if (rp == NULL) {
411 cip->errNo = kErrMallocFailed;
412 result = cip->errNo;
413 } else {
415 result = RCmd(cip, rp, "FEAT");
416 if (result < kNoErr) {
417 DoneWithResponse(cip, rp);
418 return (result);
419 } else if (result != 2) {
420 /* We cheat here and pre-populate some
421 * fields when the server is wu-ftpd.
422 * This server is very common and we
423 * know it has always had these.
424 */
425 if (cip->serverType == kServerTypeWuFTPd) {
426 cip->hasPASV = kCommandAvailable;
427 cip->hasSIZE = kCommandAvailable;
428 cip->hasMDTM = kCommandAvailable;
429 cip->hasREST = kCommandAvailable;
430 cip->NLSTfileParamWorks = kCommandAvailable;
431 } else if (cip->serverType == kServerTypeNcFTPd) {
432 cip->hasPASV = kCommandAvailable;
433 cip->hasSIZE = kCommandAvailable;
434 cip->hasMDTM = kCommandAvailable;
435 cip->hasREST = kCommandAvailable;
436 cip->NLSTfileParamWorks = kCommandAvailable;
437 }
438
439 /* Newer commands are only shown in FEAT,
440 * so we don't have to do the "try it,
441 * then save that it didn't work" thing.
442 */
443 cip->hasMLST = kCommandNotAvailable;
444 cip->hasMLSD = kCommandNotAvailable;
445 } else {
446 cip->hasFEAT = kCommandAvailable;
447
448 for (lp = rp->msg.first; lp != NULL; lp = lp->next) {
449 /* If first character was not a space it is
450 * either:
451 *
452 * (a) The header line in the response;
453 * (b) The trailer line in the response;
454 * (c) A protocol violation.
455 */
456 cp = lp->line;
457 if (*cp++ != ' ')
458 continue;
459 if (ISTRNCMP(cp, "PASV", 4) == 0) {
460 cip->hasPASV = kCommandAvailable;
461 } else if (ISTRNCMP(cp, "SIZE", 4) == 0) {
462 cip->hasSIZE = kCommandAvailable;
463 } else if (ISTRNCMP(cp, "MDTM", 4) == 0) {
464 cip->hasMDTM = kCommandAvailable;
465 } else if (ISTRNCMP(cp, "REST", 4) == 0) {
466 cip->hasREST = kCommandAvailable;
467 } else if (ISTRNCMP(cp, "UTIME", 5) == 0) {
468 cip->hasUTIME = kCommandAvailable;
469 } else if (ISTRNCMP(cp, "MLST", 4) == 0) {
470 cip->hasMLST = kCommandAvailable;
471 cip->hasMLSD = kCommandAvailable;
472 FTPExamineMlstFeatures(cip, cp + 5);
473 } else if (ISTRNCMP(cp, "CLNT", 4) == 0) {
474 cip->hasCLNT = kCommandAvailable;
475 } else if (ISTRNCMP(cp, "Compliance Level: ", 18) == 0) {
476 /* Probably only NcFTPd will ever implement this.
477 * But we use it internally to differentiate
478 * between different NcFTPd implementations of
479 * IETF extensions.
480 */
481 cip->ietfCompatLevel = atoi(cp + 18);
482 }
483 }
484 }
485
486 ReInitResponse(cip, rp);
487 result = RCmd(cip, rp, "HELP SITE");
488 if (result == 2) {
489 for (lp = rp->msg.first; lp != NULL; lp = lp->next) {
490 cp = lp->line;
491 if (strstr(cp, "RETRBUFSIZE") != NULL)
492 cip->hasRETRBUFSIZE = kCommandAvailable;
493 if (strstr(cp, "RBUFSZ") != NULL)
494 cip->hasRBUFSZ = kCommandAvailable;
495 /* See if RBUFSIZ matches (but not STORBUFSIZE) */
496 if (
497 ((p = strstr(cp, "RBUFSIZ")) != NULL) &&
498 (
499 (p == cp) ||
500 ((p > cp) && (!isupper(p[-1])))
501 )
502 )
503 cip->hasRBUFSIZ = kCommandAvailable;
504 if (strstr(cp, "STORBUFSIZE") != NULL)
505 cip->hasSTORBUFSIZE = kCommandAvailable;
506 if (strstr(cp, "SBUFSIZ") != NULL)
507 cip->hasSBUFSIZ = kCommandAvailable;
508 if (strstr(cp, "SBUFSZ") != NULL)
509 cip->hasSBUFSZ = kCommandAvailable;
510 if (strstr(cp, "BUFSIZE") != NULL)
511 cip->hasBUFSIZE = kCommandAvailable;
512 }
513 }
514 DoneWithResponse(cip, rp);
515 }
516
517 return (kNoErr);
518} /* FTPQueryFeatures */
GLfloat GLfloat p
Definition: glext.h:8902
static void FTPExamineMlstFeatures(const FTPCIPtr cip, const char *features)
Definition: open.c:338
#define ISTRNCMP
Definition: util.h:29
#define kResponseNoPrint
Definition: ncftp.h:308
#define kServerTypeWuFTPd
Definition: ncftp.h:462
#define kServerTypeNetWareFTP
Definition: ncftp.h:472

Referenced by FTPOpenHost().

◆ FTPRebuildConnectionInfo()

int FTPRebuildConnectionInfo ( const FTPLIPtr  lip,
const FTPCIPtr  cip 
)

Definition at line 1041 of file open.c.

1042{
1043 char *buf;
1044
1045 cip->lip = lip;
1046 cip->debugLog = NULL;
1047 cip->errLog = NULL;
1048 cip->debugLogProc = NULL;
1049 cip->errLogProc = NULL;
1050 cip->buf = NULL;
1051 cip->cin = NULL;
1052 cip->cout = NULL;
1053 cip->errNo = 0;
1054 cip->progress = NULL;
1055 cip->rname = NULL;
1056 cip->lname = NULL;
1057 cip->onConnectMsgProc = NULL;
1058 cip->redialStatusProc = NULL;
1059 cip->printResponseProc = NULL;
1060 cip->onLoginMsgProc = NULL;
1061 cip->passphraseProc = NULL;
1064
1065 (void) memset(&cip->lastFTPCmdResultLL, 0, sizeof(LineList));
1066
1067 /* Allocate a new buffer. */
1068 buf = (char *) calloc((size_t) 1, cip->bufSize);
1069 if (buf == NULL) {
1070 cip->errNo = kErrMallocFailed;
1071 return (kErrMallocFailed);
1072 }
1073 cip->buf = buf;
1074
1075 /* Reattach the FILE pointers for use with the Std I/O library
1076 * routines.
1077 */
1078 if ((cip->cin = _fdopen(cip->ctrlSocketR, "r")) == NULL) {
1079 cip->errNo = kErrFdopenR;
1082 return (kErrFdopenR);
1083 }
1084
1085 if ((cip->cout = _fdopen(cip->ctrlSocketW, "w")) == NULL) {
1086 CloseFile(&cip->cin);
1087 cip->errNo = kErrFdopenW;
1090 return (kErrFdopenW);
1091 }
1092
1093#if USE_SIO
1094 if (InitSReadlineInfo(&cip->ctrlSrl, cip->ctrlSocketR, cip->srlBuf, sizeof(cip->srlBuf), (int) cip->ctrlTimeout, 1) < 0) {
1095 cip->errNo = kErrFdopenW;
1096 CloseFile(&cip->cin);
1097 cip->errNo = kErrFdopenW;
1100 return (kErrFdopenW);
1101 }
1102#endif
1103 return (kNoErr);
1104} /* FTPRebuildConnectionInfo */
_Check_return_ _CRTIMP FILE *__cdecl _fdopen(_In_ int _FileHandle, _In_z_ const char *_Mode)
void CloseFile(FILE **f)
Definition: util.c:327
#define kErrFdopenW
Definition: ncftp_errno.h:26
#define calloc
Definition: rosglue.h:14
FILE * cout
Definition: ncftp.h:189
FTPPrintResponseProc printResponseProc
Definition: ncftp.h:226
char srlBuf[768]
Definition: ncftp.h:239
FTPLogProc errLogProc
Definition: ncftp.h:148
LineList lastFTPCmdResultLL
Definition: ncftp.h:215
FTPProgressMeterProc progress
Definition: ncftp.h:198
const char * asciiFilenameExtensions
Definition: ncftp.h:246
FTPConnectMessageProc onConnectMsgProc
Definition: ncftp.h:224
FILE * debugLog
Definition: ncftp.h:145
FILE * errLog
Definition: ncftp.h:146
const char * rname
Definition: ncftp.h:208
const char * lname
Definition: ncftp.h:209
SReadlineInfo ctrlSrl
Definition: ncftp.h:240
FILE * cin
Definition: ncftp.h:188
FTPLogProc debugLogProc
Definition: ncftp.h:147

◆ FTPRemoteGlob()

int FTPRemoteGlob ( FTPCIPtr  cip,
LineListPtr  fileList,
const char pattern,
int  doGlob 
)

Definition at line 1341 of file glob.c.

1342{
1343 char *cp;
1344 const char *lsflags;
1345 LinePtr lp;
1346 int result;
1347
1348 if (cip == NULL)
1349 return (kErrBadParameter);
1350 if (strcmp(cip->magic, kLibraryMagic))
1351 return (kErrBadMagic);
1352
1353 if (fileList == NULL)
1354 return (kErrBadParameter);
1355 InitLineList(fileList);
1356
1357 if ((pattern == NULL) || (pattern[0] == '\0'))
1358 return (kErrBadParameter);
1359
1360 /* Note that we do attempt to use glob characters even if the remote
1361 * host isn't UNIX. Most non-UNIX remote FTP servers look for UNIX
1362 * style wildcards.
1363 */
1364 if ((doGlob == 1) && (GLOBCHARSINSTR(pattern))) {
1365 /* Use NLST, which lists files one per line. */
1366 lsflags = "";
1367
1368 /* Optimize for "NLST *" case which is same as "NLST". */
1369 if (strcmp(pattern, "*") == 0) {
1370 pattern = "";
1371 } else if (strcmp(pattern, "**") == 0) {
1372 /* Hack; Lets you try "NLST -a" if you're daring. */
1373 pattern = "";
1374 lsflags = "-a";
1375 }
1376
1377 if ((result = FTPListToMemory2(cip, pattern, fileList, lsflags, 0, (int *) 0)) < 0) {
1378 if (*lsflags == '\0')
1379 return (result);
1380 /* Try again, without "-a" */
1381 lsflags = "";
1382 if ((result = FTPListToMemory2(cip, pattern, fileList, lsflags, 0, (int *) 0)) < 0) {
1383 return (result);
1384 }
1385 }
1386 if (fileList->first == NULL) {
1387 cip->errNo = kErrGlobNoMatch;
1388 return (kErrGlobNoMatch);
1389 }
1390 if (fileList->first == fileList->last) {
1391#define glberr(a) (ISTRNEQ(cp, a, strlen(a)))
1392 /* If we have only one item in the list, see if it really was
1393 * an error message we would recognize.
1394 */
1395 cp = strchr(fileList->first->line, ':');
1396 if (cp != NULL) {
1397 if (glberr(": No such file or directory")) {
1398 (void) RemoveLine(fileList, fileList->first);
1399 cip->errNo = kErrGlobFailed;
1400 return (kErrGlobFailed);
1401 } else if (glberr(": No match")) {
1402 cip->errNo = kErrGlobNoMatch;
1403 return (kErrGlobNoMatch);
1404 }
1405 }
1406 }
1407 RemoteGlobCollapse(pattern, fileList);
1408 for (lp=fileList->first; lp != NULL; lp = lp->next)
1409 PrintF(cip, " Rglob [%s]\n", lp->line);
1410 } else {
1411 /* Or, if there were no globbing characters in 'pattern', then the
1412 * pattern is really just a filename. So for this case the
1413 * file list is really just a single file.
1414 */
1415 fileList->first = fileList->last = NULL;
1416 (void) AddLine(fileList, pattern);
1417 }
1418 return (kNoErr);
1419} /* FTPRemoteGlob */
#define glberr(a)
static void RemoteGlobCollapse(const char *pattern, LineListPtr fileList)
Definition: glob.c:43
LinePtr RemoveLine(LineListPtr list, LinePtr killMe)
Definition: linelist.c:63
#define kErrGlobNoMatch
Definition: ncftp_errno.h:89
#define kErrGlobFailed
Definition: ncftp_errno.h:68

Referenced by ChdirCmd(), FTPChmod(), FTPDelete(), FTPFtwL2(), FTPGetFiles3(), FTPRmdir(), FTPRmdirRecursiveL2(), RGlobCmd(), and SpoolGetCmd().

◆ FTPRemoteHelp()

int FTPRemoteHelp ( const  FTPCIPtr,
const char * const  pattern,
const  LineListPtr 
)

Definition at line 739 of file cmds.c.

740{
741 int result;
742 ResponsePtr rp;
743
744 if ((cip == NULL) || (llp == NULL))
745 return (kErrBadParameter);
746 if (strcmp(cip->magic, kLibraryMagic))
747 return (kErrBadMagic);
748
749 InitLineList(llp);
750 rp = InitResponse();
751 if (rp == NULL) {
753 cip->errNo = kErrMallocFailed;
754 Error(cip, kDontPerror, "Malloc failed.\n");
755 } else {
756 if ((pattern == NULL) || (*pattern == '\0'))
757 result = RCmd(cip, rp, "HELP");
758 else
759 result = RCmd(cip, rp, "HELP %s", pattern);
760 if (result < 0) {
761 DoneWithResponse(cip, rp);
762 return (result);
763 } else if (result == 2) {
764 if (CopyLineList(llp, &rp->msg) < 0) {
766 cip->errNo = kErrMallocFailed;
767 Error(cip, kDontPerror, "Malloc failed.\n");
768 } else {
769 result = kNoErr;
770 }
771 } else {
772 cip->errNo = kErrHELPFailed;
774 }
775 DoneWithResponse(cip, rp);
776 }
777 return (result);
778} /* FTPRemoteHelp */
int CopyLineList(LineListPtr dst, LineListPtr src)
Definition: linelist.c:127
#define kErrHELPFailed
Definition: ncftp_errno.h:83

Referenced by RmtHelpCmd().

◆ FTPRemoteRecursiveFileList()

int FTPRemoteRecursiveFileList ( FTPCIPtr  cip,
LineListPtr  fileList,
FileInfoListPtr  files 
)

Definition at line 1032 of file glob.c.

1033{
1034 LinePtr filePtr, nextFilePtr;
1035 LineList dirContents;
1036 FileInfoList fil;
1037 char cwd[512];
1038 int result;
1039 char *rdir;
1040
1041 if ((result = FTPGetCWD(cip, cwd, sizeof(cwd))) < 0)
1042 return (result);
1043
1044 InitFileInfoList(files);
1045
1046 for (filePtr = fileList->first;
1047 filePtr != NULL;
1048 filePtr = nextFilePtr)
1049 {
1050 nextFilePtr = filePtr->next;
1051
1052 rdir = filePtr->line;
1053 if (rdir == NULL)
1054 continue;
1055
1056 if (FTPChdir(cip, rdir) < 0) {
1057 /* Probably not a directory.
1058 * Just add it as a plain file
1059 * to the list.
1060 */
1061 (void) ConcatFileToFileInfoList(files, rdir);
1062 continue;
1063 }
1064
1065 /* Paths collected must be relative. */
1066 if ((result = FTPListToMemory2(cip, "", &dirContents, "-lRa", 1, (int *) 0)) < 0) {
1067 goto goback;
1068 }
1069
1070 (void) UnLslR(&fil, &dirContents, cip->serverType);
1071 DisposeLineListContents(&dirContents);
1072 (void) ComputeRNames(&fil, rdir, 1, 1);
1073 (void) ConcatFileInfoList(files, &fil);
1075
1076goback:
1077 if ((result = FTPChdir(cip, cwd)) < 0) {
1078 return (result);
1079 }
1080 }
1081 return (kNoErr);
1082} /* FTPRemoteRecursiveFileList */
int UnLslR(FileInfoListPtr filp, LineListPtr llp, int serverType)
Definition: glob.c:561
int ConcatFileInfoList(FileInfoListPtr dst, FileInfoListPtr src)
Definition: linelist.c:556
int ConcatFileToFileInfoList(FileInfoListPtr dst, char *rfile)
Definition: linelist.c:740
int ComputeRNames(FileInfoListPtr dst, const char *dstdir, int pflag, int nochop)
Definition: linelist.c:579
void DisposeFileInfoListContents(FileInfoListPtr list)
Definition: linelist.c:152

◆ FTPRemoteRecursiveFileList1()

int FTPRemoteRecursiveFileList1 ( FTPCIPtr  cip,
char * const  rdir,
FileInfoListPtr  files 
)

Definition at line 983 of file glob.c.

984{
985 LineList dirContents;
986 FileInfoList fil;
987 char cwd[512];
988 int result;
989
990 if ((result = FTPGetCWD(cip, cwd, sizeof(cwd))) < 0)
991 return (result);
992
993 InitFileInfoList(files);
994
995 if (rdir == NULL)
996 return (-1);
997
998 if (FTPChdir(cip, rdir) < 0) {
999 /* Probably not a directory.
1000 * Just add it as a plain file
1001 * to the list.
1002 */
1003 (void) ConcatFileToFileInfoList(files, rdir);
1004 return (kNoErr);
1005 }
1006
1007 /* Paths collected must be relative. */
1008 if ((result = FTPListToMemory2(cip, "", &dirContents, "-lRa", 1, (int *) 0)) < 0) {
1009 if ((result = FTPChdir(cip, cwd)) < 0) {
1010 return (result);
1011 }
1012 }
1013
1014 (void) UnLslR(&fil, &dirContents, cip->serverType);
1015 DisposeLineListContents(&dirContents);
1016 /* Could sort it to breadth-first here. */
1017 /* (void) SortRecursiveFileList(&fil); */
1018 (void) ComputeRNames(&fil, rdir, 1, 1);
1019 (void) ConcatFileInfoList(files, &fil);
1021
1022 if ((result = FTPChdir(cip, cwd)) < 0) {
1023 return (result);
1024 }
1025 return (kNoErr);
1026} /* FTPRemoteRecursiveFileList1 */

Referenced by FTPGetFiles3().

◆ FTPRename()

int FTPRename ( const FTPCIPtr  cip,
const char *const  oldname,
const char *const  newname 
)

Definition at line 703 of file cmds.c.

704{
705 int result;
706
707 if (cip == NULL)
708 return (kErrBadParameter);
709 if (strcmp(cip->magic, kLibraryMagic))
710 return (kErrBadMagic);
711 if ((oldname == NULL) || (oldname[0] == '\0'))
712 return (kErrBadParameter);
713 if ((newname == NULL) || (oldname[0] == '\0'))
714 return (kErrBadParameter);
715
716
717 result = FTPCmd(cip, "RNFR %s", oldname);
718 if (result < 0)
719 return (result);
720 if (result != 3) {
721 cip->errNo = kErrRenameFailed;
722 return (cip->errNo);
723 }
724
725 result = FTPCmd(cip, "RNTO %s", newname);
726 if (result < 0)
727 return (result);
728 if (result != 2) {
729 cip->errNo = kErrRenameFailed;
730 return (cip->errNo);
731 }
732 return (kNoErr);
733} /* FTPRename */
#define kErrRenameFailed
Definition: ncftp_errno.h:67

Referenced by FTPPutOneF(), and RenameCmd().

◆ FTPRmdir()

int FTPRmdir ( const FTPCIPtr  cip,
const char *const  pattern,
const int  recurse,
const int  doGlob 
)

Definition at line 784 of file cmds.c.

785{
786 LineList fileList;
787 LinePtr filePtr;
788 char *file;
789 int onceResult, batchResult;
790
791 if (cip == NULL)
792 return (kErrBadParameter);
793 if (strcmp(cip->magic, kLibraryMagic))
794 return (kErrBadMagic);
795
796 batchResult = FTPRemoteGlob(cip, &fileList, pattern, doGlob);
797 if (batchResult != kNoErr)
798 return (batchResult);
799
800 for (batchResult = kNoErr, filePtr = fileList.first;
801 filePtr != NULL;
802 filePtr = filePtr->next)
803 {
804 file = filePtr->line;
805 if (file == NULL) {
806 batchResult = kErrBadLineList;
807 cip->errNo = kErrBadLineList;
808 break;
809 }
810 onceResult = FTPCmd(cip, "RMD %s", file);
811 if (onceResult < 0) {
812 batchResult = onceResult;
813 break;
814 }
815 if (onceResult != 2) {
816 if (recurse == kRecursiveYes) {
817 onceResult = FTPRmdirRecursive(cip, file);
818 if (onceResult < 0) {
819 batchResult = kErrRMDFailed;
820 cip->errNo = kErrRMDFailed;
821 }
822 } else {
823 batchResult = kErrRMDFailed;
824 cip->errNo = kErrRMDFailed;
825 }
826 }
827 }
828 DisposeLineListContents(&fileList);
829 return (batchResult);
830} /* FTPRmdir */

Referenced by FTPRmdirRecursive(), FTPRmdirRecursiveL2(), and RmdirCmd().

◆ FTPSetTransferType()

int FTPSetTransferType ( const  FTPCIPtr,
int  type 
)

Definition at line 836 of file cmds.c.

837{
838 int result;
839
840 if (cip == NULL)
841 return (kErrBadParameter);
842 if (strcmp(cip->magic, kLibraryMagic))
843 return (kErrBadMagic);
844
845 if (cip->curTransferType != type) {
846 switch (type) {
847 case kTypeAscii:
848 case kTypeBinary:
849 case kTypeEbcdic:
850 break;
851 case 'i':
852 case 'b':
853 case 'B':
855 break;
856 case 'e':
858 break;
859 case 'a':
861 break;
862 default:
863 /* Yeah, we don't support Tenex. Who cares? */
864 Error(cip, kDontPerror, "Bad transfer type [%c].\n", type);
865 cip->errNo = kErrBadTransferType;
866 return (kErrBadTransferType);
867 }
868 result = FTPCmd(cip, "TYPE %c", type);
869 if (result != 2) {
871 cip->errNo = kErrTYPEFailed;
872 return (result);
873 }
874 cip->curTransferType = type;
875 }
876 return (kNoErr);
877} /* FTPSetTransferType */
#define kTypeEbcdic
Definition: ncftp.h:355
#define kErrTYPEFailed
Definition: ncftp_errno.h:64
#define kErrBadTransferType
Definition: ncftp_errno.h:38

Referenced by FTPFileSize(), FTPFileSizeAndModificationTime(), FTPGetOneF(), FTPPutOneF(), FTPStartDataCmd(), and TypeCmd().

◆ FTPShutdownHost()

void FTPShutdownHost ( const FTPCIPtr  cip)

Definition at line 564 of file open.c.

565{
566#ifdef SIGPIPE
567 FTPSigProc osigpipe;
568#endif
569
570 if (cip == NULL)
571 return;
572 if (strcmp(cip->magic, kLibraryMagic))
573 return;
574
575#ifdef SIGPIPE
576 osigpipe = signal(SIGPIPE, (FTPSigProc) SIG_IGN);
577#endif
578
579 /* Linger could cause close to block, so unset it. */
581 (void) SetLinger(cip, cip->dataSocket, 0);
582 CloseDataConnection(cip); /* Shouldn't be open normally. */
583
584 /* Linger should already be turned off for this. */
586
588
589#ifdef SIGPIPE
590 (void) signal(SIGPIPE, (FTPSigProc) osigpipe);
591#endif
592} /* FTPShutdownHost */
#define SIG_IGN
Definition: signal.h:48

Referenced by CommandShell(), FTPGetOneF(), FTPListToMemory2(), FTPPutOneF(), and GetResponse().

◆ FTPStartDataCmd()

int FTPStartDataCmd ( const  FTPCIPtr,
int  netMode,
int  type,
longest_int  startPoint,
const char cmdspec,
  ... 
)

Definition at line 763 of file rcmd.c.

764{
765 va_list ap;
766 int result;
767 int respCode;
768 ResponsePtr rp;
769
770 if (cip == NULL)
771 return (kErrBadParameter);
772 if (strcmp(cip->magic, kLibraryMagic))
773 return (kErrBadMagic);
774
776 if (result < 0)
777 return (result);
778
779 /* Re-set the cancellation flag. */
780 cip->cancelXfer = 0;
781
782 /* To transfer data, we do these things in order as specifed by
783 * the RFC.
784 *
785 * First, we tell the other side to set up a data line. This
786 * is done below by calling OpenDataConnection(), which sets up
787 * the socket. When we do that, the other side detects a connection
788 * attempt, so it knows we're there. Then tell the other side
789 * (by using listen()) that we're willing to receive a connection
790 * going to our side.
791 */
792
793 if ((result = OpenDataConnection(cip, cip->dataPortMode)) < 0)
794 goto done;
795
796 /* If asked, attempt to start at a later position in the remote file. */
797 if (startPoint != (longest_int) 0) {
798 if ((startPoint == kSizeUnknown) || ((result = SetStartOffset(cip, startPoint)) != 0))
799 startPoint = (longest_int) 0;
800 }
801 cip->startPoint = startPoint;
802
803 /* Now we tell the server what we want to do. This sends the
804 * the type of transfer we want (RETR, STOR, LIST, etc) and the
805 * parameters for that (files to send, directories to list, etc).
806 */
807 va_start(ap, cmdspec);
808#ifndef NO_SIGNALS
809 if (cip->ctrlTimeout > 0)
810 (void) alarm(cip->ctrlTimeout);
811#endif /* NO_SIGNALS */
812 result = SendCommand(cip, cmdspec, ap);
813 va_end(ap);
814 if (result < 0) {
815#ifndef NO_SIGNALS
816 if (cip->ctrlTimeout > 0)
817 (void) alarm(0);
818#endif /* NO_SIGNALS */
819 goto done;
820 }
821
822 /* Get the response to the transfer command we sent, to see if
823 * they can accomodate the request. If everything went okay,
824 * we will get a preliminary response saying that the transfer
825 * initiation was successful and that the data is there for
826 * reading (for retrieves; for sends, they will be waiting for
827 * us to send them something).
828 */
829 rp = InitResponse();
830 if (rp == NULL) {
831 Error(cip, kDontPerror, "Malloc failed.\n");
832 cip->errNo = kErrMallocFailed;
833 result = cip->errNo;
834 goto done;
835 }
836 result = GetResponse(cip, rp);
837#ifndef NO_SIGNALS
838 if (cip->ctrlTimeout > 0)
839 (void) alarm(0);
840#endif /* NO_SIGNALS */
841
842 if (result < 0)
843 goto done;
844 respCode = rp->codeType;
845 DoneWithResponse(cip, rp);
846
847 if (respCode > 2) {
849 result = cip->errNo;
850 goto done;
851 }
852
853 /* Now we accept the data connection that the other side is offering
854 * to us. Then we can do the actual I/O on the data we want.
855 */
856 cip->netMode = netMode;
857 if ((result = AcceptDataConnection(cip)) < 0)
858 goto done;
859 return (kNoErr);
860
861done:
862 (void) FTPEndDataCmd(cip, 0);
863 return (result);
864} /* FTPStartDataCmd */
int OpenDataConnection(const FTPCIPtr cip, int mode)
Definition: ftp.c:1053
int SetStartOffset(const FTPCIPtr cip, longest_int restartPt)
Definition: ftp.c:853
int AcceptDataConnection(const FTPCIPtr cip)
Definition: ftp.c:1249
#define kErrCouldNotStartDataTransfer
Definition: ncftp_errno.h:77
int FTPEndDataCmd(const FTPCIPtr cip, int didXfer)
Definition: rcmd.c:933

Referenced by FTPGetOneF(), FTPList(), FTPListToMemory2(), and FTPPutOneF().

◆ FTPStartIOTimer()

void FTPStartIOTimer ( const  FTPCIPtr)

Definition at line 93 of file io.c.

94{
95 (void) gettimeofday(&cip->t0, NULL);
96 if (cip->progress != (FTPProgressMeterProc) 0)
97 (*cip->progress)(cip, kPrInitMsg);
98} /* FTPStartIOTimer */
#define kPrInitMsg
Definition: ncftp.h:290
void(* FTPProgressMeterProc)(const FTPCIPtr, int)
Definition: ncftp.h:125

Referenced by FTPGetOneF(), and FTPPutOneF().

◆ FTPStopIOTimer()

void FTPStopIOTimer ( const  FTPCIPtr)

Definition at line 159 of file io.c.

160{
161 cip->nextProgressUpdate = 0; /* force last update */
162 FTPUpdateIOTimer(cip);
163 if (cip->progress != (FTPProgressMeterProc) 0)
164 (*cip->progress)(cip, kPrEndMsg);
165} /* FTPStopIOTimer */
void FTPUpdateIOTimer(const FTPCIPtr cip)
Definition: io.c:104
#define kPrEndMsg
Definition: ncftp.h:292

Referenced by FTPGetOneF(), and FTPPutOneF().

◆ FTPStrError()

const char * FTPStrError ( int  e)

Definition at line 114 of file errno.c.

115{
116 if (e == kErrGeneric) {
117 return ("miscellaneous error");
118 } else if (e == kNoErr) {
119 return ("no error");
120 } else {
121 if (e < 0)
122 e = -e;
123 if ((e >= kErrFirst) && (e <= kErrLast)) {
124 return (gErrList[e - kErrFirst]);
125 }
126 }
127 return ("unrecognized error number");
128} /* FTPStrError */
#define e
Definition: ke_i.h:82
static const char * gErrList[kErrLast - kErrFirst+2]
Definition: errno.c:11
#define kErrFirst
Definition: ncftp_errno.h:16
#define kErrLast
Definition: ncftp_errno.h:113

Referenced by FTPPerror(), FTPPutOneF(), InitConnectionInfo(), and PreInit().

◆ FTPSymlink()

int FTPSymlink ( const FTPCIPtr  cip,
const char *const  lfrom,
const char *const  lto 
)

Definition at line 1585 of file cmds.c.

1586{
1587 if (strcmp(cip->magic, kLibraryMagic))
1588 return (kErrBadMagic);
1589 if ((cip == NULL) || (lfrom == NULL) || (lto == NULL))
1590 return (kErrBadParameter);
1591 if ((lfrom[0] == '\0') || (lto[0] == '\0'))
1592 return (kErrBadParameter);
1593 if (FTPCmd(cip, "SITE SYMLINK %s %s", lfrom, lto) == 2)
1594 return (kNoErr);
1595 return (kErrSYMLINKFailed);
1596} /* FTPSymlink */
#define kErrSYMLINKFailed
Definition: ncftp_errno.h:87

Referenced by FTPPutFiles3(), and SymlinkCmd().

◆ FTPUmask()

int FTPUmask ( const FTPCIPtr  cip,
const char *const  umsk 
)

Definition at line 1602 of file cmds.c.

1603{
1604 if (cip == NULL)
1605 return (kErrBadParameter);
1606 if (strcmp(cip->magic, kLibraryMagic))
1607 return (kErrBadMagic);
1608 if ((umsk == NULL) || (umsk[0] == '\0'))
1609 return (kErrBadParameter);
1610 if (FTPCmd(cip, "SITE UMASK %s", umsk) == 2)
1611 return (kNoErr);
1612 return (kErrUmaskFailed);
1613} /* FTPUmask */
#define kErrUmaskFailed
Definition: ncftp_errno.h:60

Referenced by UmaskCmd().

◆ FTPUpdateIOTimer()

void FTPUpdateIOTimer ( const  FTPCIPtr)

Definition at line 104 of file io.c.

105{
106 double sec;
107 struct timeval *t0, t1;
108 time_t now;
109
110 (void) time(&now);
111 if (now < cip->nextProgressUpdate)
112 return;
113 now += 1;
114 cip->nextProgressUpdate = now;
115
116 (void) gettimeofday(&t1, NULL);
117 t0 = &cip->t0;
118
119 if (t0->tv_usec > t1.tv_usec) {
120 t1.tv_usec += 1000000;
121 t1.tv_sec--;
122 }
123 sec = ((double) (t1.tv_usec - t0->tv_usec) * 0.000001)
124 + (t1.tv_sec - t0->tv_sec);
125 if (sec > 0.0) {
126 cip->kBytesPerSec = ((double) cip->bytesTransferred) / (1024.0 * sec);
127 } else {
128 cip->kBytesPerSec = -1.0;
129 }
130 if (cip->expectedSize == kSizeUnknown) {
131 cip->percentCompleted = -1.0;
132 cip->secLeft = -1.0;
133 } else if (cip->expectedSize <= 0) {
134 cip->percentCompleted = 100.0;
135 cip->secLeft = 0.0;
136 } else {
137 cip->percentCompleted = ((double) (100.0 * (cip->bytesTransferred + cip->startPoint))) / ((double) cip->expectedSize);
138 if (cip->percentCompleted >= 100.0) {
139 cip->percentCompleted = 100.0;
140 cip->secLeft = 0.0;
141 } else if (cip->percentCompleted <= 0.0) {
142 cip->secLeft = 999.0;
143 }
144 if (cip->kBytesPerSec > 0.0) {
145 cip->secLeft = ((cip->expectedSize - cip->bytesTransferred - cip->startPoint) / 1024.0) / cip->kBytesPerSec;
146 if (cip->secLeft < 0.0)
147 cip->secLeft = 0.0;
148 }
149 }
150 cip->sec = sec;
151 if ((cip->progress != (FTPProgressMeterProc) 0) && (cip->useProgressMeter != 0))
152 (*cip->progress)(cip, kPrUpdateMsg);
153} /* FTPUpdateIOTimer */
time_t now
Definition: finger.c:65
static const char mbstate_t *static wchar_t const char mbstate_t *static const wchar_t int *static double
Definition: string.c:80
#define kPrUpdateMsg
Definition: ncftp.h:291
unsigned long tv_sec
Definition: linux.h:1738
unsigned long tv_usec
Definition: linux.h:1739

Referenced by FTPGetOneF(), FTPPutOneF(), FTPStopIOTimer(), WaitForRemoteInput(), and WaitForRemoteOutput().

◆ FTPUtime()

int FTPUtime ( const FTPCIPtr  cip,
const char *const  file,
time_t  actime,
time_t  modtime,
time_t  crtime 
)

Definition at line 1649 of file cmds.c.

1650{
1651 char mstr[64], astr[64], cstr[64];
1652 int result;
1653 ResponsePtr rp;
1654
1655 if (cip == NULL)
1656 return (kErrBadParameter);
1657 if (strcmp(cip->magic, kLibraryMagic))
1658 return (kErrBadMagic);
1659
1660 if (cip->hasUTIME == kCommandNotAvailable) {
1663 } else {
1664 if ((actime == (time_t) 0) || (actime == (time_t) -1))
1665 (void) time(&actime);
1666 if ((modtime == (time_t) 0) || (modtime == (time_t) -1))
1667 (void) time(&modtime);
1668 if ((crtime == (time_t) 0) || (crtime == (time_t) -1))
1669 crtime = modtime;
1670
1671 (void) GmTimeStr(astr, sizeof(astr), actime);
1672 (void) GmTimeStr(mstr, sizeof(mstr), modtime);
1673 (void) GmTimeStr(cstr, sizeof(cstr), crtime);
1674
1675 rp = InitResponse();
1676 if (rp == NULL) {
1678 cip->errNo = kErrMallocFailed;
1679 Error(cip, kDontPerror, "Malloc failed.\n");
1680 } else {
1681 result = RCmd(cip, rp, "SITE UTIME %s %s %s %s UTC", file, astr, mstr, cstr);
1682 if (result < 0) {
1683 DoneWithResponse(cip, rp);
1684 return (result);
1685 } else if (result == 2) {
1687 result = kNoErr;
1688 } else if (UNIMPLEMENTED_CMD(rp->code)) {
1692 } else {
1693 cip->errNo = kErrUTIMEFailed;
1695 }
1696 DoneWithResponse(cip, rp);
1697 }
1698 }
1699 return (result);
1700} /* FTPUtime */
void modtime(int argc, const char *argv[])
Definition: cmds.c:2232
static void GmTimeStr(char *const dst, const size_t dstsize, time_t t)
Definition: cmds.c:1619
#define kErrUTIMEFailed
Definition: ncftp_errno.h:81
#define kErrUTIMENotAvailable
Definition: ncftp_errno.h:82

Referenced by FTPPutOneF().

◆ GetHomeDir()

void GetHomeDir ( char dst,
size_t  size 
)

Definition at line 240 of file util.c.

241{
242#if defined(WIN32) || defined(_WINDOWS)
243 const char *homedrive, *homepath;
244
245 homedrive = getenv("HOMEDRIVE");
246 homepath = getenv("HOMEPATH");
247 if ((homedrive != NULL) && (homepath != NULL)) {
248 (void) Strncpy(dst, homedrive, size);
249 (void) Strncat(dst, homepath, size);
250 return;
251 }
252
253// GetSpecialDir(dst, size, CSIDL_PERSONAL /* "My Documents" */);
254// if (dst[0] != '\0')
255// return;
256//
257// dst[0] = '\0';
258// if (GetWindowsDirectory(dst, size - 1) < 1)
259// (void) Strncpy(dst, ".", size);
260// else if (dst[1] == ':') {
261// dst[2] = '\\';
262// dst[3] = '\0';
263// }
264#else
265 const char *cp;
266 struct passwd *pw;
267
268 pw = NULL;
269#if defined(USE_GETPWUID)
270 /* Try to use getpwuid(), but if we have to, fall back to getpwnam(). */
271 if ((pw = getpwuid(getuid())) == NULL)
272 pw = GetPwByName(); /* Oh well, try getpwnam() then. */
273#else
274 /* Try to use getpwnam(), but if we have to, fall back to getpwuid(). */
275 if ((pw = GetPwByName()) == NULL)
276 pw = getpwuid(getuid()); /* Try getpwnam() then. */
277#endif
278 if (pw != NULL)
279 cp = pw->pw_dir;
280 else if ((cp = (const char *) getenv("LOGNAME")) == NULL)
281 cp = ".";
282 (void) Strncpy(dst, cp, size);
283#endif
284} /* GetHomeDir */
char * Strncat(char *const, const char *const, const size_t)
Definition: Strncat.c:13
uid_t getuid()
Definition: uid.c:27
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
struct passwd * GetPwByName(void)
Definition: util.c:165

Referenced by ExpandTilde().

◆ GetPass()

char * GetPass ( const char *const  prompt)

Definition at line 186 of file util.c.

187{
188#ifdef HAVE_GETPASS
189 return getpass(prompt);
190#elif defined(_CONSOLE) && (defined(WIN32) || defined(_WINDOWS))
191 static char pwbuf[128];
192 char *dst, *dlim;
193 int c;
194
195 (void) memset(pwbuf, 0, sizeof(pwbuf));
196 if (! _isatty(_fileno(stdout)))
197 return (pwbuf);
198 (void) fputs(prompt, stdout);
199 (void) fflush(stdout);
200
201 for (dst = pwbuf, dlim = dst + sizeof(pwbuf) - 1;;) {
202 c = _getch();
203 if ((c == 0) || (c == 0xe0)) {
204 /* The key is a function or arrow key; read and discard. */
205 (void) _getch();
206 }
207 if ((c == '\r') || (c == '\n'))
208 break;
209 if (dst < dlim)
210 *dst++ = c;
211 }
212 *dst = '\0';
213
214 (void) fflush(stdout);
215 (void) fflush(stdin);
216 return (pwbuf);
217#else
218 static char pwbuf[128];
219
220 (void) memset(pwbuf, 0, sizeof(pwbuf));
221#if defined(WIN32) || defined(_WINDOWS)
222 if (! _isatty(_fileno(stdout)))
223#else
224 if (! isatty(1))
225#endif
226 return (pwbuf);
227 (void) fputs(prompt, stdout);
228 (void) fflush(stdout);
229 (void) FGets(pwbuf, sizeof(pwbuf), stdin);
230 (void) fflush(stdout);
231 (void) fflush(stdin);
232 return (pwbuf);
233#endif
234} /* GetPass */
#define isatty
Definition: acwin.h:103
char * getpass(const char *prompt)
Definition: fake.c:231
#define stdout
Definition: stdio.h:99
_Check_return_ _CRTIMP int __cdecl _fileno(_In_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fputs(_In_z_ const char *_Str, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
#define stdin
Definition: stdio.h:98
char * FGets(char *str, size_t size, FILE *fp)
Definition: util.c:111
_Check_return_ _CRTIMP int __cdecl _isatty(_In_ int _FileHandle)
int _getch()
Definition: getch.c:16

Referenced by DECLARE_INTERFACE_().

◆ GetResponse()

int GetResponse ( const  FTPCIPtr,
ResponsePtr  rp 
)

Definition at line 287 of file rcmd.c.

288{
290 int eofError;
291 str16 code;
292 char *cp;
293 int continuation;
294 volatile FTPCIPtr vcip;
295#ifdef NO_SIGNALS
296 int result;
297#else /* NO_SIGNALS */
298 volatile FTPSigProc osigpipe;
299 int sj;
300#endif /* NO_SIGNALS */
301
302 /* RFC 959 states that a reply may span multiple lines. A single
303 * line message would have the 3-digit code <space> then the msg.
304 * A multi-line message would have the code <dash> and the first
305 * line of the msg, then additional lines, until the last line,
306 * which has the code <space> and last line of the msg.
307 *
308 * For example:
309 * 123-First line
310 * Second line
311 * 234 A line beginning with numbers
312 * 123 The last line
313 */
314
315#ifdef NO_SIGNALS
316 vcip = cip;
317#else /* NO_SIGNALS */
318 osigpipe = (volatile FTPSigProc) signal(SIGPIPE, BrokenCtrl);
319 vcip = cip;
320
321#ifdef HAVE_SIGSETJMP
322 sj = sigsetjmp(gBrokenCtrlJmp, 1);
323#else
324 sj = setjmp(gBrokenCtrlJmp);
325#endif /* HAVE_SIGSETJMP */
326
327 if (sj != 0) {
328 (void) signal(SIGPIPE, (FTPSigProc) osigpipe);
329 FTPShutdownHost(vcip);
331 return(vcip->errNo);
332 }
333#endif /* NO_SIGNALS */
334
335#ifdef NO_SIGNALS
336 cp = str;
337 eofError = 0;
338 if (cip->dataTimedOut > 0) {
339 /* Give up immediately unless the server had already
340 * sent a message. Odds are since the data is timed
341 * out, so is the control.
342 */
343 if (SWaitUntilReadyForReading(cip->ctrlSocketR, 0) == 0) {
344 /* timeout */
345 Error(cip, kDontPerror, "Could not read reply from control connection -- timed out.\n");
346 FTPShutdownHost(vcip);
347 cip->errNo = kErrControlTimedOut;
348 return (cip->errNo);
349 }
350 }
351 result = SReadline(&cip->ctrlSrl, str, sizeof(str) - 1);
352 if (result == kTimeoutErr) {
353 /* timeout */
354 Error(cip, kDontPerror, "Could not read reply from control connection -- timed out.\n");
355 FTPShutdownHost(vcip);
356 cip->errNo = kErrControlTimedOut;
357 return (cip->errNo);
358 } else if (result == 0) {
359 /* eof */
360 eofError = 1;
361 rp->hadEof = 1;
362 if (rp->eofOkay == 0)
363 Error(cip, kDontPerror, "Remote host has closed the connection.\n");
364 FTPShutdownHost(vcip);
366 return (cip->errNo);
367 } else if (result < 0) {
368 /* error */
369 Error(cip, kDoPerror, "Could not read reply from control connection");
370 FTPShutdownHost(vcip);
371 cip->errNo = kErrInvalidReplyFromServer;
372 return (cip->errNo);
373 }
374
375 if (str[result - 1] == '\n')
376 str[result - 1] = '\0';
377
378#else /* NO_SIGNALS */
379 /* Get the first line of the response. */
380 eofError = GetTelnetString(cip, str, sizeof(str), cip->cin, cip->cout);
381
382 cp = str;
383 if (*cp == '\0') {
384 if (eofError < 0) {
385 /* No bytes read for reply, and EOF detected. */
386 rp->hadEof = 1;
387 if (rp->eofOkay == 0)
388 Error(cip, kDontPerror, "Remote host has closed the connection.\n");
389 FTPShutdownHost(vcip);
391 (void) signal(SIGPIPE, osigpipe);
392 return(cip->errNo);
393 }
394 }
395#endif /* NO_SIGNALS */
396
397 if (!isdigit((int) *cp)) {
398 Error(cip, kDontPerror, "Invalid reply: \"%s\"\n", cp);
399 cip->errNo = kErrInvalidReplyFromServer;
400#ifndef NO_SIGNALS
401 (void) signal(SIGPIPE, osigpipe);
402#endif
403 return (cip->errNo);
404 }
405
406 rp->codeType = *cp - '0';
407 cp += 3;
408 continuation = (*cp == '-');
409 *cp++ = '\0';
410 (void) STRNCPY(code, str);
411 rp->code = atoi(code);
412 (void) AddLine(&rp->msg, cp);
413 if (eofError < 0) {
414 /* Read reply, but EOF was there also. */
415 rp->hadEof = 1;
416 }
417
418 while (continuation) {
419
420#ifdef NO_SIGNALS
421 result = SReadline(&cip->ctrlSrl, str, sizeof(str) - 1);
422 if (result == kTimeoutErr) {
423 /* timeout */
424 Error(cip, kDontPerror, "Could not read reply from control connection -- timed out.\n");
425 FTPShutdownHost(vcip);
426 cip->errNo = kErrControlTimedOut;
427 return (cip->errNo);
428 } else if (result == 0) {
429 /* eof */
430 eofError = 1;
431 rp->hadEof = 1;
432 if (rp->eofOkay == 0)
433 Error(cip, kDontPerror, "Remote host has closed the connection.\n");
434 FTPShutdownHost(vcip);
436 return (cip->errNo);
437 } else if (result < 0) {
438 /* error */
439 Error(cip, kDoPerror, "Could not read reply from control connection");
440 FTPShutdownHost(vcip);
441 cip->errNo = kErrInvalidReplyFromServer;
442 return (cip->errNo);
443 }
444
445 if (str[result - 1] == '\n')
446 str[result - 1] = '\0';
447#else /* NO_SIGNALS */
448 eofError = GetTelnetString(cip, str, sizeof(str), cip->cin, cip->cout);
449 if (eofError < 0) {
450 /* Read reply, but EOF was there also. */
451 rp->hadEof = 1;
452 continuation = 0;
453 }
454#endif /* NO_SIGNALS */
455 cp = str;
456 if (strncmp(code, cp, SZ(3)) == 0) {
457 cp += 3;
458 if (*cp == ' ')
459 continuation = 0;
460 ++cp;
461 }
462 (void) AddLine(&rp->msg, cp);
463 }
464
465 if (rp->code == 421) {
466 /*
467 * 421 Service not available, closing control connection.
468 * This may be a reply to any command if the service knows it
469 * must shut down.
470 */
471 if (rp->eofOkay == 0)
472 Error(cip, kDontPerror, "Remote host has closed the connection.\n");
473 FTPShutdownHost(vcip);
475#ifndef NO_SIGNALS
476 (void) signal(SIGPIPE, osigpipe);
477#endif
478 return(cip->errNo);
479 }
480
481#ifndef NO_SIGNALS
482 (void) signal(SIGPIPE, osigpipe);
483#endif
484 return (kNoErr);
485} /* GetResponse */
#define isdigit(c)
Definition: acclib.h:68
char str16[16]
Definition: util.h:11
char longstring[512]
Definition: util.h:12
#define SZ(a)
Definition: util.h:49
int SWaitUntilReadyForReading(const int sfd, const int tlen)
Definition: SWait.c:7
int GetTelnetString(const FTPCIPtr, char *, size_t, FILE *, FILE *)
#define kErrControlTimedOut
Definition: ncftp_errno.h:110
#define kErrInvalidReplyFromServer
Definition: ncftp_errno.h:74
int hadEof
Definition: ncftp.h:95
Definition: inflate.c:139

Referenced by FTPAbortDataTransfer(), FTPCmd(), FTPEndDataCmd(), FTPStartDataCmd(), OpenControlConnection(), and RCmd().

◆ GetTelnetString()

int GetTelnetString ( const  FTPCIPtr,
char ,
size_t  ,
FILE ,
FILE  
)

Referenced by GetResponse().

◆ GetUsrName()

void GetUsrName ( char dst,
size_t  size 
)

Definition at line 290 of file util.c.

291{
292#if defined(WIN32) || defined(_WINDOWS)
293 DWORD size1;
294
295 size1 = size - 1;
296 if (! GetUserName(dst, &size1))
297 (void) strncpy(dst, "unknown", size);
298 dst[size - 1] = '\0';
299#else
300 const char *cp;
301 struct passwd *pw;
302
303 pw = NULL;
304#ifdef USE_GETPWUID
305 /* Try to use getpwuid(), but if we have to, fall back to getpwnam(). */
306 if ((pw = getpwuid(getuid())) == NULL)
307 pw = GetPwByName(); /* Oh well, try getpwnam() then. */
308#else
309 /* Try to use getpwnam(), but if we have to, fall back to getpwuid(). */
310 if ((pw = GetPwByName()) == NULL)
311 pw = getpwuid(getuid()); /* Try getpwnam() then. */
312#endif
313 if (pw != NULL)
314 cp = pw->pw_name;
315 else if ((cp = (const char *) getenv("LOGNAME")) == NULL)
316 cp = "UNKNOWN";
317 (void) Strncpy(dst, cp, size);
318#endif
319} /* GetUserName */
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define GetUserName
Definition: winbase.h:3851

Referenced by FTPInitializeAnonPassword().

◆ InitFileInfo()

void InitFileInfo ( FileInfoPtr  fip)

Definition at line 471 of file linelist.c.

472{
473 (void) memset(fip, 0, sizeof(FileInfo));
474 fip->type = '-';
475 fip->size = kSizeUnknown;
476 fip->mdtm = kModTimeUnknown;
477} /* InitFileInfoList */
longest_int size
Definition: ncftp.h:260
int type
Definition: ncftp.h:258
time_t mdtm
Definition: ncftp.h:259

Referenced by ConcatFileToFileInfoList().

◆ InitFileInfoList()

void InitFileInfoList ( FileInfoListPtr  list)

◆ InitLineList()

◆ InitResponse()

◆ LineListToFileInfoList()

int LineListToFileInfoList ( LineListPtr  src,
FileInfoListPtr  dst 
)

Definition at line 758 of file linelist.c.

759{
760 LinePtr lp, lp2;
761
763 for (lp = src->first; lp != NULL; lp = lp2) {
764 lp2 = lp->next;
765 if (ConcatFileToFileInfoList(dst, lp->line) < 0)
766 return (-1);
767 }
768 return (0);
769} /* LineListToFileList */

Referenced by FTPPutFiles3().

◆ LineToFileInfoList()

int LineToFileInfoList ( LinePtr  lp,
FileInfoListPtr  dst 
)

Definition at line 775 of file linelist.c.

776{
778 if (ConcatFileToFileInfoList(dst, lp->line) < 0)
779 return (-1);
780 return (0);
781} /* LineToFileInfoList */

Referenced by FTPGetFiles3().

◆ MkDirs()

int MkDirs ( const char * const  newdir,
int  mode1 
)

Definition at line 785 of file util.c.

786{
787 char s[512];
788 int rc;
789 char *cp, *sl;
790#if defined(WIN32) || defined(_WINDOWS)
791 struct _stat st;
792 char *share;
793#else
794 struct Stat st;
795 mode_t mode = (mode_t) mode1;
796#endif
797
798#if defined(WIN32) || defined(_WINDOWS)
799 if ((isalpha(newdir[0])) && (newdir[1] == ':')) {
800 if (! IsLocalPathDelim(newdir[2])) {
801 /* Special case "c:blah", and errout.
802 * "c:\blah" must be used or _access GPFs.
803 */
804 errno = EINVAL;
805 return (-1);
806 } else if (newdir[3] == '\0') {
807 /* Special case root directory, which cannot be made. */
808 return (0);
809 }
810 } else if (IsUNCPrefixed(newdir)) {
811 share = StrFindLocalPathDelim(newdir + 2);
812 if ((share == NULL) || (StrFindLocalPathDelim(share + 1) == NULL))
813 return (-1);
814 }
815
816 if (_access(newdir, 00) == 0) {
817 if (_stat(newdir, &st) < 0)
818 return (-1);
819 if (! S_ISDIR(st.st_mode)) {
820 errno = ENOTDIR;
821 return (-1);
822 }
823 return 0;
824 }
825#else
826 if (access(newdir, F_OK) == 0) {
827 if (Stat(newdir, &st) < 0)
828 return (-1);
829 if (! S_ISDIR(st.st_mode)) {
830 errno = ENOTDIR;
831 return (-1);
832 }
833 return 0;
834 }
835#endif
836
837 (void) strncpy(s, newdir, sizeof(s));
838 if (s[sizeof(s) - 1] != '\0') {
839#ifdef ENAMETOOLONG
841#else
842 errno = EINVAL;
843 return (-1);
844#endif
845 }
846
848 if (cp == NULL) {
849#if defined(WIN32) || defined(_WINDOWS)
850 if (! CreateDirectory(newdir, (LPSECURITY_ATTRIBUTES) 0))
851 return (-1);
852 return (0);
853#else
854 rc = mkdir(newdir, mode);
855 return (rc);
856#endif
857 } else if (cp[1] == '\0') {
858 /* Remove trailing slashes from path. */
859 --cp;
860 while (cp > s) {
861 if (! IsLocalPathDelim(*cp))
862 break;
863 --cp;
864 }
865 cp[1] = '\0';
867 if (cp == NULL) {
868#if defined(WIN32) || defined(_WINDOWS)
870 return (-1);
871#else
872 rc = mkdir(s, mode);
873 return (rc);
874#endif
875 }
876 }
877
878 /* Find the deepest directory in this
879 * path that already exists. When
880 * we do, we want to have the 's'
881 * string as it was originally, but
882 * with 'cp' pointing to the first
883 * slash in the path that starts the
884 * part that does not exist.
885 */
886 sl = NULL;
887 for (;;) {
888 *cp = '\0';
889#if defined(WIN32) || defined(_WINDOWS)
890 rc = _access(s, 00);
891#else
892 rc = access(s, F_OK);
893#endif
894 if (sl != NULL)
895 *sl = LOCAL_PATH_DELIM;
896 if (rc == 0) {
898 break;
899 }
900 sl = cp;
902 if (cp == NULL) {
903 /* We do not have any more
904 * slashes, so none of the
905 * new directory's components
906 * existed before, so we will
907 * have to make everything
908 * starting at the first node.
909 */
910 if (sl != NULL)
911 *sl = LOCAL_PATH_DELIM;
912
913 /* We refer to cp + 1 below,
914 * so this is why we can
915 * set "cp" to point to the
916 * byte before the array starts.
917 */
918 cp = s - 1;
919 break;
920 }
921 }
922
923 for (;;) {
924 /* Extend the path we have to
925 * include the next component
926 * to make.
927 */
928 sl = StrFindLocalPathDelim(cp + 1);
929 if (sl == s) {
930 /* If the next slash is pointing
931 * to the start of the string, then
932 * the path is an absolute path and
933 * we don't need to make the root node,
934 * and besides the next mkdir would
935 * try an empty string.
936 */
937 ++cp;
938 sl = StrFindLocalPathDelim(cp + 1);
939 }
940 if (sl != NULL) {
941 *sl = '\0';
942 }
943#if defined(WIN32) || defined(_WINDOWS)
945 return (-1);
946#else
947 rc = mkdir(s, mode);
948 if (rc < 0)
949 return rc;
950#endif
951 if (sl == NULL)
952 break;
953 *sl = LOCAL_PATH_DELIM;
954 cp = sl;
955 }
956 return (0);
957} /* MkDirs */
#define EINVAL
Definition: acclib.h:90
#define isalpha(c)
Definition: acclib.h:74
#define mkdir
Definition: acwin.h:101
#define ENOTDIR
Definition: errno.h:26
__kernel_mode_t mode_t
Definition: linux.h:199
#define IsUNCPrefixed(s)
Definition: getline.c:59
GLdouble s
Definition: gl.h:2039
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
#define F_OK
Definition: util.h:52
#define LOCAL_PATH_DELIM
Definition: ncftp.h:492
#define ENAMETOOLONG
Definition: errno.h:55
_Check_return_ _CRTIMP int __cdecl _access(_In_z_ const char *_Filename, _In_ int _AccessMode)
Definition: stat.h:40
#define CreateDirectory
Definition: winbase.h:3746

Referenced by FTPGetFiles3(), InitOurDirectory(), LocalMkdirCmd(), and MkSpoolDir().

◆ PrintResponse()

void PrintResponse ( const  FTPCIPtr,
LineListPtr  llp 
)

Definition at line 74 of file rcmd.c.

75{
76 LinePtr lp;
77
78 if (llp != NULL) {
79 for (lp = llp->first; lp != NULL; lp = lp->next)
80 PrintF(cip, "%s\n", lp->line);
81 }
82} /* PrintResponse */

◆ RCmd()

int RCmd ( const  FTPCIPtr,
ResponsePtr  rp,
const char cmdspec,
  ... 
)

Definition at line 718 of file rcmd.c.

719{
720 va_list ap;
721 int result;
722
723 if (cip == NULL)
724 return (kErrBadParameter);
725 if (strcmp(cip->magic, kLibraryMagic))
726 return (kErrBadMagic);
727
728 va_start(ap, cmdspec);
729#ifndef NO_SIGNALS
730 if (cip->ctrlTimeout > 0)
731 (void) alarm(cip->ctrlTimeout);
732#endif /* NO_SIGNALS */
733 result = SendCommand(cip, cmdspec, ap);
734 va_end(ap);
735 if (result < 0) {
736#ifndef NO_SIGNALS
737 if (cip->ctrlTimeout > 0)
738 (void) alarm(0);
739#endif /* NO_SIGNALS */
740 return (result);
741 }
742
743 /* Get the response to the command we sent. */
744 result = GetResponse(cip, rp);
745#ifndef NO_SIGNALS
746 if (cip->ctrlTimeout > 0)
747 (void) alarm(0);
748#endif /* NO_SIGNALS */
749
750 if (result == kNoErr)
751 result = rp->codeType;
752 return (result);
753} /* RCmd */

Referenced by FTPChdirAndGetCWD(), FTPCloseHost(), FTPFileExistsStat(), FTPFileModificationTime(), FTPFileSize(), FTPGetCWD(), FTPLoginHost(), FTPMListOneFile(), FTPQueryFeatures(), FTPRemoteHelp(), FTPUtime(), nFTPChdirAndGetCWD(), Passive(), SendPort(), and SetStartOffset().

◆ ReInitResponse()

void ReInitResponse ( const  FTPCIPtr,
ResponsePtr  rp 
)

Definition at line 142 of file rcmd.c.

143{
144 if (rp != NULL) {
145 TraceResponse(cip, rp);
146 if (cip->printResponseProc != 0) {
147 if ((rp->printMode & kResponseNoProc) == 0)
148 (*cip->printResponseProc)(cip, rp);
149 }
150 if ((rp->printMode & kResponseNoSave) == 0)
151 SaveLastResponse(cip, rp);
152 else
154 (void) memset(rp, 0, sizeof(Response));
155 }
156} /* ReInitResponse */

Referenced by FTPLoginHost(), and FTPQueryFeatures().

◆ RemoveFileInfo()

FileInfoPtr RemoveFileInfo ( FileInfoListPtr  list,
FileInfoPtr  killMe 
)

Definition at line 483 of file linelist.c.

484{
485 FileInfoPtr nextFileInfo, prevFileInfo;
486
487 nextFileInfo = killMe->next;
488 prevFileInfo = killMe->prev;
489 if (killMe->lname != NULL) {
490 killMe->lname[0] = '\0'; /* Make it useless just in case. */
491 free(killMe->lname);
492 }
493 if (killMe->relname != NULL) {
494 killMe->relname[0] = '\0';
495 free(killMe->relname);
496 }
497 if (killMe->rname != NULL) {
498 killMe->rname[0] = '\0';
499 free(killMe->rname);
500 }
501 if (killMe->rlinkto != NULL) {
502 killMe->rlinkto[0] = '\0';
503 free(killMe->rlinkto);
504 }
505 if (killMe->plug != NULL) {
506 killMe->plug[0] = '\0';
507 free(killMe->plug);
508 }
509
510 if (list->first == killMe)
511 list->first = nextFileInfo;
512 if (list->last == killMe)
513 list->last = prevFileInfo;
514
515 if (nextFileInfo != NULL)
516 nextFileInfo->prev = prevFileInfo;
517 if (prevFileInfo != NULL)
518 prevFileInfo->next = nextFileInfo;
519
520 free(killMe);
521 list->nFileInfos--;
522 return (nextFileInfo);
523} /* RemoveFileInfo */

◆ RemoveLine()

LinePtr RemoveLine ( LineListPtr  list,
LinePtr  killMe 
)

Definition at line 63 of file linelist.c.

64{
65 LinePtr nextLine, prevLine;
66
67 nextLine = killMe->next;
68 prevLine = killMe->prev;
69 if (killMe->line != NULL) {
70 killMe->line[0] = '\0'; /* Make it useless just in case. */
71 free(killMe->line);
72 }
73
74 if (list->first == killMe)
75 list->first = nextLine;
76 if (list->last == killMe)
77 list->last = prevLine;
78
79 if (nextLine != NULL)
80 nextLine->prev = prevLine;
81 if (prevLine != NULL)
82 prevLine->next = nextLine;
83
84 free(killMe);
85 list->nLines--;
86 return (nextLine);
87} /* RemoveLine */

Referenced by FTPRemoteGlob(), and RemoteGlobCollapse().

◆ Scramble()

void Scramble ( unsigned char dst,
size_t  dsize,
unsigned char src,
char key 
)

Definition at line 607 of file util.c.

608{
609 int i;
610 unsigned int ch;
611 unsigned char *k2;
612 size_t keyLen;
613
614 keyLen = strlen(key);
615 k2 = (unsigned char *) key;
616 for (i=0; i < (int) dsize - 1; i++) {
617 ch = src[i];
618 if (ch == 0)
619 break;
620 dst[i] = (unsigned char) (ch ^ (int) (k2[i % (int) keyLen]));
621 }
622 dst[i] = '\0';
623} /* Scramble */
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
Definition: copy.c:22

◆ SortFileInfoList()

void SortFileInfoList ( FileInfoListPtr  list,
int  sortKey,
int  sortOrder 
)

Definition at line 353 of file linelist.c.

354{
355 FileInfoVec fiv;
356 FileInfoPtr fip;
357 int i, j, n, n2;
358
359 fiv = list->vec;
360 if (fiv == NULL)
361 return;
362
363 if (list->sortKey == sortKey) {
364 if (list->sortOrder == sortOrder)
365 return; /* Already sorted they you want. */
366
367 /* Reverse the sort. */
368 n = list->nFileInfos;
369 if (n > 1) {
370 n2 = n / 2;
371 for (i=0; i<n2; i++) {
372 j = n - i - 1;
373 fip = fiv[i];
374 fiv[i] = fiv[j];
375 fiv[j] = fip;
376 }
377 }
378
379 list->sortOrder = sortOrder;
380 } else if ((sortKey == 'n') && (sortOrder == 'a')) {
381 qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
382 NameCmp);
383 list->sortKey = sortKey;
384 list->sortOrder = sortOrder;
385 } else if ((sortKey == 'n') && (sortOrder == 'd')) {
386 qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
388 list->sortKey = sortKey;
389 list->sortOrder = sortOrder;
390 } else if ((sortKey == 't') && (sortOrder == 'a')) {
391 qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
392 TimeCmp);
393 list->sortKey = sortKey;
394 list->sortOrder = sortOrder;
395 } else if ((sortKey == 't') && (sortOrder == 'd')) {
396 qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
398 list->sortKey = sortKey;
399 list->sortOrder = sortOrder;
400 } else if ((sortKey == 's') && (sortOrder == 'a')) {
401 qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
402 SizeCmp);
403 list->sortKey = sortKey;
404 list->sortOrder = sortOrder;
405 } else if ((sortKey == 's') && (sortOrder == 'd')) {
406 qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
408 list->sortKey = sortKey;
409 list->sortOrder = sortOrder;
410 } else if (sortKey == 'b') {
411 /* This is different from the rest. */
412 list->sortKey = sortKey;
413 list->sortOrder = sortOrder;
414 qsort(fiv, (size_t) list->nFileInfos, sizeof(FileInfoPtr),
416 }
417} /* SortFileInfoList */
GLdouble n
Definition: glext.h:7729
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static int NameCmp(const void *a, const void *b)
Definition: linelist.c:287
static int ReverseNameCmp(const void *a, const void *b)
Definition: linelist.c:270
static int ReverseTimeCmp(const void *a, const void *b)
Definition: linelist.c:219
static int TimeCmp(const void *a, const void *b)
Definition: linelist.c:202
static int ReverseSizeCmp(const void *a, const void *b)
Definition: linelist.c:253
static int BreadthFirstCmp(const void *a, const void *b)
Definition: linelist.c:304
static int SizeCmp(const void *a, const void *b)
Definition: linelist.c:236
int n2
Definition: dwarfget.c:147
void __cdecl qsort(_Inout_updates_bytes_(_NumOfElements *_SizeOfElements) void *_Base, _In_ size_t _NumOfElements, _In_ size_t _SizeOfElements, _In_ int(__cdecl *_PtFuncCompare)(const void *, const void *))

Referenced by GetLsCacheFileList(), and Ls().

◆ StrDup()

char * StrDup ( const char buf)

Definition at line 12 of file linelist.c.

13{
14 char *cp;
15 size_t len;
16
17 if (buf == NULL)
18 return (NULL);
19
20 len = strlen(buf) + 1;
21 cp = (char *) malloc(len);
22 if (cp != NULL)
23 (void) memcpy(cp, buf, len);
24 return (cp);
25} /* StrDup */

◆ StrRemoveTrailingSlashes()

void StrRemoveTrailingSlashes ( char dst)

Definition at line 768 of file util.c.

769{
770 char *cp;
771
772 cp = strrchr(dst, '/');
773 if ((cp == NULL) || (cp[1] != '\0'))
774 return;
775
776 /* Note: Do not destroy a path of "/" */
777 while ((cp > dst) && (*cp == '/'))
778 *cp-- = '\0';
779} /* StrRemoveTrailingSlashes */

Referenced by FTPGetFiles3(), GetCmd(), PutCmd(), SpoolGetCmd(), and SpoolPutCmd().

◆ TraceResponse()

void TraceResponse ( const  FTPCIPtr,
ResponsePtr  rp 
)

Definition at line 55 of file rcmd.c.

56{
57 LinePtr lp;
58
59 if (rp != NULL) {
60 lp = rp->msg.first;
61 if (lp != NULL) {
62 PrintF(cip, "%3d: %s\n", rp->code, lp->line);
63 for (lp = lp->next; lp != NULL; lp = lp->next)
64 PrintF(cip, " %s\n", lp->line);
65 }
66 }
67} /* TraceResponse */

Referenced by DoneWithResponse(), and ReInitResponse().

◆ UnLslR()

int UnLslR ( FileInfoListPtr  filp,
LineListPtr  llp,
int  serverType 
)

Definition at line 561 of file glob.c.

562{
563 char curdir[256];
564 char line[256];
565 int hadblankline = 0;
566 int len;
567 size_t curdirlen = 0;
568 char fname[256];
569 char linkto[256];
570 char *cp;
572 int ftype;
574 int thisyear;
575 struct tm *nowtm;
576 int rc;
577 LinePtr lp;
578 FileInfo fi;
579 int linesread = 0;
580 int linesconverted = 0;
581 size_t maxFileLen = 0;
582 size_t maxPlugLen = 0;
583 size_t fileLen;
584 int plugend;
585
586 (void) time(&now);
587 nowtm = localtime(&now);
588 if (nowtm == NULL)
589 thisyear = 1970; /* should never happen */
590 else
591 thisyear = nowtm->tm_year + 1900;
592
593 curdir[0] = '\0';
594
595 InitFileInfoList(filp);
596 for (lp = llp->first; lp != NULL; lp = lp->next) {
597 len = (int) strlen(STRNCPY(line, lp->line));
598 if ((line[0] == 't') && (strncmp(line, "total", 5) == 0)) {
599 /* total XX line? */
600 if (line[len - 1] != ':') {
601 hadblankline = 0;
602 continue;
603 }
604 /* else it was a subdir named total */
605 } else {
606 for (cp = line; ; cp++) {
607 if ((*cp == '\0') || (!isspace((int) *cp)))
608 break;
609 }
610 if (*cp == '\0') {
611 /* Entire line was blank. */
612 /* separator line between dirs */
613 hadblankline = 1;
614 continue;
615 }
616 }
617
618 if ((hadblankline != 0) && (line[len - 1] == ':')) {
619 /* newdir */
620 hadblankline = 0;
621 if ((line[0] == '.') && (line[1] == '/')) {
622 line[len - 1] = '/';
623 (void) memcpy(curdir, line + 2, (size_t) len + 1 - 2);
624 curdirlen = (size_t) (len - 2);
625 } else if ((line[0] == '.') && (line[1] == '\\')) {
626 line[len - 1] = '\\';
627 (void) memcpy(curdir, line + 2, (size_t) len + 1 - 2);
628 curdirlen = (size_t) (len - 2);
629 } else {
630 line[len - 1] = '/';
631 (void) memcpy(curdir, line, (size_t) len + 1);
632 curdirlen = (size_t) len;
633 }
634 continue;
635 }
636
637 linesread++;
638 rc = UnLslRLine(line, curdir, curdirlen, fname, sizeof(fname), linkto, sizeof(linkto), &ftype, &fsize, &ftime, now, thisyear, &plugend);
639 if ((rc < 0) && (serverType == kServerTypeMicrosoftFTP)) {
640 rc = UnDosLine(line, curdir, curdirlen, fname, sizeof(fname), &ftype, &fsize, &ftime);
641 if (rc == 0) {
642 *linkto = '\0';
643 plugend = 0;
644 }
645 }
646 if (rc == 0) {
647 linesconverted++;
648 fileLen = strlen(fname);
649 if (fileLen > maxFileLen)
650 maxFileLen = fileLen;
651 fi.relnameLen = fileLen;
652 fi.relname = StrDup(fname);
653 fi.rname = NULL;
654 fi.lname = NULL;
655 fi.rlinkto = (linkto[0] == '\0') ? NULL : StrDup(linkto);
656 fi.mdtm = ftime;
657 fi.size = (longest_int) fsize;
658 fi.type = ftype;
659 if (plugend > 0) {
660 fi.plug = (char *) malloc((size_t) plugend + 1);
661 if (fi.plug != NULL) {
662 (void) memcpy(fi.plug, line, (size_t) plugend);
663 fi.plug[plugend] = '\0';
664 if ((size_t) plugend > maxPlugLen)
665 maxPlugLen = (size_t) plugend;
666 }
667 } else {
668 fi.plug = (char *) malloc(32);
669 if (fi.plug != NULL) {
670 strcpy(fi.plug, "---------- 1 ftpuser ftpusers");
671 fi.plug[0] = (char) ftype;
672 if (30 > maxPlugLen)
673 maxPlugLen = (size_t) 30;
674 }
675 }
676 (void) AddFileInfo(filp, &fi);
677 }
678
679 hadblankline = 0;
680 }
681
682 filp->maxFileLen = maxFileLen;
683 filp->maxPlugLen = maxPlugLen;
684 if (linesread == 0)
685 return (0);
686 return ((linesconverted > 0) ? linesconverted : (-1));
687} /* UnLslR */
#define isspace(c)
Definition: acclib.h:69
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
GLint fsize
Definition: glext.h:9408
static int UnLslRLine(char *const line, const char *const curdir, size_t curdirlen, char *fname, size_t fnamesize, char *linkto, size_t linktosize, int *ftype, longest_int *fsize, time_t *ftime, time_t now, int thisyear, int *plugend)
Definition: glob.c:353
static int UnDosLine(char *const line, const char *const curdir, size_t curdirlen, char *fname, size_t fnamesize, int *ftype, longest_int *fsize, time_t *ftime)
Definition: glob.c:175
#define kServerTypeMicrosoftFTP
Definition: ncftp.h:465
_CRTIMP struct tm *__cdecl localtime(const time_t *_Time)
Definition: time.h:416
size_t maxFileLen
Definition: ncftp.h:267
size_t maxPlugLen
Definition: ncftp.h:268
size_t relnameLen
Definition: ncftp.h:261
Definition: time.h:68
int tm_year
Definition: time.h:74
__CRT_INLINE void __cdecl ftime(struct timeb *_Tmb)
Definition: timeb.h:96

Referenced by FTPRemoteRecursiveFileList(), FTPRemoteRecursiveFileList1(), and Ls().

◆ UnMDTMDate()

time_t UnMDTMDate ( char dstr)

Definition at line 486 of file util.c.

487{
488#ifndef HAVE_MKTIME
489 return (kModTimeUnknown);
490#else
491 struct tm ut, *t;
492 time_t mt, now;
494
495 if (strncmp(dstr, "19100", 5) == 0) {
496 /* Server Y2K bug! */
497 return (result);
498 }
499
500 (void) time(&now);
501 t = localtime(&now);
502
503 /* Copy the whole structure of the 'tm' pointed to by t, so it will
504 * also set all fields we don't specify explicitly to be the same as
505 * they were in t. That way we copy non-standard fields such as
506 * tm_gmtoff, if it exists or not.
507 */
508 ut = *t;
509
510 /* The time we get back from the server is (should be) in UTC. */
511 if (sscanf(dstr, "%04d%02d%02d%02d%02d%02d",
512 &ut.tm_year,
513 &ut.tm_mon,
514 &ut.tm_mday,
515 &ut.tm_hour,
516 &ut.tm_min,
517 &ut.tm_sec) == 6)
518 {
519 --ut.tm_mon;
520 ut.tm_year -= 1900;
521 mt = mktime(&ut);
522 if (mt != (time_t) -1) {
523 mt += GetUTCOffset(ut.tm_mon, ut.tm_mday);
524 result = (time_t) mt;
525 }
526 }
527 return result;
528#endif /* HAVE_MKTIME */
529} /* UnMDTMDate */
GLdouble GLdouble t
Definition: gl.h:2047
static time_t GetUTCOffset(int mon, int mday)
Definition: util.c:449
_CRTIMP time_t __cdecl mktime(struct tm *_Tm)
Definition: time.h:418

Referenced by FTPFileModificationTime(), and UnMlsT().

◆ UnMlsD()

int UnMlsD ( FileInfoListPtr  filp,
LineListPtr  llp 
)

Definition at line 827 of file glob.c.

828{
829 MLstItem mli;
830 char plug[64];
831 char og[32];
832 int rc;
833 LinePtr lp;
834 FileInfo fi;
835 int linesread = 0;
836 int linesconverted = 0;
837 int linesignored = 0;
838 size_t maxFileLen = 0;
839 size_t maxPlugLen = 0;
840 size_t fileLen, plugLen;
841 int m1, m2, m3;
842 const char *cm1, *cm2, *cm3;
843
844 InitFileInfoList(filp);
845 for (lp = llp->first; lp != NULL; lp = lp->next) {
846 linesread++;
847 rc = UnMlsT(lp->line, &mli);
848 if (rc == 0) {
849 linesconverted++;
850 fileLen = strlen(mli.fname);
851 if (fileLen > maxFileLen)
852 maxFileLen = fileLen;
853 fi.relnameLen = fileLen;
854 fi.relname = StrDup(mli.fname);
855 fi.rname = NULL;
856 fi.lname = NULL;
857 fi.rlinkto = (mli.linkto[0] == '\0') ? NULL : StrDup(mli.linkto);
858 fi.mdtm = mli.ftime;
859 fi.size = (longest_int) mli.fsize;
860 fi.type = mli.ftype;
861 plug[0] = (char) mli.ftype;
862 plug[1] = '\0';
863 m1 = 0;
864 m2 = 0;
865 m3 = -1;
866 if (mli.mode != (-1)) {
867 m1 = (mli.mode & 00700) >> 6;
868 m2 = (mli.mode & 00070) >> 3;
869 m3 = (mli.mode & 00007);
870 }
871 if (mli.perm[0] != '\0') {
872 m3 = 0;
873 if (fi.type == 'd') {
874 if (strchr(mli.perm, 'e') != NULL) {
875 /* execute -> execute */
876 m3 |= 00001;
877 }
878 if (strchr(mli.perm, 'c') != NULL) {
879 /* create -> write */
880 m3 |= 00002;
881 }
882 if (strchr(mli.perm, 'l') != NULL) {
883 /* list -> read */
884 m3 |= 00004;
885 }
886 } else {
887 if (strchr(mli.perm, 'w') != NULL) {
888 /* write -> write */
889 m3 |= 00002;
890 }
891 if (strchr(mli.perm, 'r') != NULL) {
892 /* read -> read */
893 m3 |= 00004;
894 }
895 }
896 }
897 if (m3 != (-1)) {
898 cm1 = rwx[m1];
899 cm2 = rwx[m2];
900 cm3 = rwx[m3];
901 sprintf(plug + 1, "%s%s%s", cm1, cm2, cm3);
902 }
903 if (mli.owner[0] != '\0') {
904 if (mli.group[0] != '\0') {
905#ifdef HAVE_SNPRINTF
906 snprintf(og, sizeof(og) - 1,
907#else
908 sprintf(og,
909#endif /* HAVE_SNPRINTF */
910 " %-8.8s %s",
911 mli.owner, mli.group
912 );
913 STRNCAT(plug, og);
914 } else {
915 STRNCAT(plug, " ");
916 STRNCAT(plug, mli.owner);
917 }
918 }
919 fi.plug = StrDup(plug);
920 if (fi.plug != NULL) {
921 plugLen = strlen(plug);
922 if (plugLen > maxPlugLen)
923 maxPlugLen = plugLen;
924 }
925 (void) AddFileInfo(filp, &fi);
926 } else if (rc == (-2)) {
927 linesignored++;
928 }
929 }
930
931 filp->maxFileLen = maxFileLen;
932 filp->maxPlugLen = maxPlugLen;
933 if (linesread == 0)
934 return (0);
935 linesconverted += linesignored;
936 return ((linesconverted > 0) ? linesconverted : (-1));
937} /* UnMlsD */
static const char * rwx[9]
Definition: glob.c:10
char fname[512]
Definition: ncftp.h:276
char perm[16]
Definition: ncftp.h:284
int mode
Definition: ncftp.h:281
char owner[16]
Definition: ncftp.h:285
char group[16]
Definition: ncftp.h:286
char linkto[512]
Definition: ncftp.h:277

Referenced by Ls().

◆ UnMlsT()

int UnMlsT ( const char * const  line0,
const  MLstItemPtr 
)

Definition at line 693 of file glob.c.

694{
695 char *cp, *val, *fact;
696 int ec;
697 size_t len;
698 char line[1024];
699
700 memset(mlip, 0, sizeof(MLstItem));
701 mlip->mode = -1;
702 mlip->fsize = kSizeUnknown;
703 mlip->ftype = '-';
704 mlip->ftime = kModTimeUnknown;
705
706 len = strlen(line0);
707 if (len > (sizeof(line) - 1))
708 return (-1); /* Line too long, sorry. */
709 /* This should be re-coded so does not need to make a
710 * copy of the buffer; it could be done in place.
711 */
712 memcpy(line, line0, len + 1);
713
714 /* Skip leading whitespace. */
715 for (cp = line; *cp != '\0'; cp++) {
716 if (! isspace(*cp))
717 break;
718 }
719
720 while (*cp != '\0') {
721 for (fact = cp; ; cp++) {
722 if ((*cp == '\0') || (*cp == ' ')) {
723 /* protocol violation */
724 return (-1);
725 }
726 if (*cp == '=') {
727 /* End of fact name. */
728 *cp++ = '\0';
729 break;
730 }
731 }
732 for (val = cp; ; cp++) {
733 if (*cp == '\0') {
734 /* protocol violation */
735 return (-1);
736 }
737 if (*cp == ' ') {
738 ec = ' ';
739 *cp++ = '\0';
740 break;
741 } else if (*cp == ';') {
742 if (cp[1] == ' ') {
743 ec = ' ';
744 *cp++ = '\0';
745 *cp++ = '\0';
746 } else {
747 ec = ';';
748 *cp++ = '\0';
749 }
750 break;
751 }
752 }
753 if (ISTRNEQ(fact, "OS.", 3))
754 fact += 3;
755 if (ISTREQ(fact, "type")) {
756 if (ISTREQ(val, "file")) {
757 mlip->ftype = '-';
758 } else if (ISTREQ(val, "dir")) {
759 mlip->ftype = 'd';
760 } else if (ISTREQ(val, "cdir")) {
761 /* not supported: current directory */
762 return (-2);
763 } else if (ISTREQ(val, "pdir")) {
764 /* not supported: parent directory */
765 return (-2);
766 } else {
767 /* ? */
768 return (-1);
769 }
770 } else if (ISTREQ(fact, "UNIX.mode")) {
771 if (val[0] == '0')
772 sscanf(val, "%o", &mlip->mode);
773 else
774 sscanf(val, "%i", &mlip->mode);
775 if (mlip->mode != (-1))
776 mlip->mode &= 00777;
777 } else if (ISTREQ(fact, "perm")) {
778 STRNCPY(mlip->perm, val);
779 } else if (ISTREQ(fact, "size")) {
780#if defined(HAVE_LONG_LONG) && defined(SCANF_LONG_LONG)
781 (void) sscanf(val, SCANF_LONG_LONG, &mlip->fsize);
782#elif defined(HAVE_LONG_LONG) && defined(HAVE_STRTOQ)
783 mlip->fsize = (longest_int) strtoq(val, NULL, 0);
784#else
785 {
786 long fsize2 = 0L;
787
788 (void) sscanf(val, "%ld", &fsize2);
789 mlip->fsize = (longest_int) fsize2;
790 }
791#endif
792 } else if (ISTREQ(fact, "modify")) {
793 mlip->ftime = UnMDTMDate(val);
794 } else if (ISTREQ(fact, "UNIX.owner")) {
795 STRNCPY(mlip->owner, val);
796 } else if (ISTREQ(fact, "UNIX.group")) {
797 STRNCPY(mlip->group, val);
798 } else if (ISTREQ(fact, "UNIX.uid")) {
799 mlip->uid = atoi(val);
800 } else if (ISTREQ(fact, "UNIX.gid")) {
801 mlip->gid = atoi(val);
802 } else if (ISTREQ(fact, "perm")) {
803 STRNCPY(mlip->perm, val);
804 }
805
806 /* End of facts? */
807 if (ec == ' ')
808 break;
809 }
810
811 len = strlen(cp);
812 if (len > (sizeof(mlip->fname) - 1)) {
813 /* Filename too long */
814 return (-1);
815 }
816 memcpy(mlip->fname, cp, len);
817
818 /* also set linkto here if used */
819
820 return (0);
821} /* UnMlsT */
GLuint GLfloat * val
Definition: glext.h:7180
#define ISTREQ(a, b)
Definition: util.h:33
#define ISTRNEQ(a, b, s)
Definition: util.h:34
#define L(x)
Definition: ntvdm.h:50

Referenced by FTPMListOneFile(), and UnMlsD().

◆ UnvectorizeFileInfoList()

void UnvectorizeFileInfoList ( FileInfoListPtr  list)

Definition at line 441 of file linelist.c.

442{
443 FileInfoVec fiv;
444 FileInfoPtr fip;
445 int i, n;
446
447 fiv = list->vec;
448 if (fiv != (FileInfoVec) 0) {
449 list->first = fiv[0];
450 n = list->nFileInfos;
451 if (n > 0) {
452 list->last = fiv[n - 1];
453 fip = fiv[0];
454 fip->prev = NULL;
455 fip->next = fiv[1];
456 for (i = 1; i < n; i++) {
457 fip = fiv[i];
458 fip->prev = fiv[i - 1];
459 fip->next = fiv[i + 1];
460 }
461 }
462 free(fiv);
463 list->vec = (FileInfoVec) 0;
464 }
465} /* UnvectorizeFileInfoList */
struct FileInfo ** FileInfoVec
Definition: ncftp.h:250

◆ URLCopyToken()

void URLCopyToken ( char dst,
size_t  dsize,
const char src,
size_t  howmuch 
)

Definition at line 598 of file open.c.

599{
600 char *dlim;
601 const char *slim;
602 unsigned int hc;
603 int c;
604 char h[4];
605
606 dlim = dst + dsize - 1; /* leave room for \0 */
607 slim = src + howmuch;
608 while (src < slim) {
609 c = *src++;
610 if (c == '\0')
611 break;
612 if (c == '%') {
613 /* hex representation */
614 if (src < slim + 2) {
615 h[0] = *src++;
616 h[1] = *src++;
617 h[2] = '\0';
618 hc = 0xeeff;
619 if ((sscanf(h, "%x", &hc) >= 0) && (hc != 0xeeff)) {
620 if (dst < dlim) {
621 *(unsigned char *)dst = (unsigned char) hc;
622 dst++;
623 }
624 }
625 } else {
626 break;
627 }
628 } else {
629 *dst++ = (char) c;
630 }
631 }
632 *dst = '\0';
633} /* URLCopyToken */
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723

Referenced by FTPDecodeURL().

◆ VectorizeFileInfoList()

void VectorizeFileInfoList ( FileInfoListPtr  list)

Definition at line 423 of file linelist.c.

424{
425 FileInfoVec fiv;
426 FileInfoPtr fip;
427 int i;
428
429 fiv = (FileInfoVec) calloc((size_t) (list->nFileInfos + 1), sizeof(FileInfoPtr));
430 if (fiv != (FileInfoVec) 0) {
431 for (i = 0, fip = list->first; fip != NULL; fip = fip->next, i++)
432 fiv[i] = fip;
433 list->vec = fiv;
434 }
435} /* VectorizeFileInfoList */

Referenced by Ls().

◆ WaitResponse()

int WaitResponse ( const  FTPCIPtr,
unsigned int  sec 
)

Definition at line 684 of file rcmd.c.

685{
686 int result;
687 fd_set ss;
688 struct timeval tv;
689 int fd;
690
691#ifdef NO_SIGNALS
692 fd = cip->ctrlSocketR;
693#else /* NO_SIGNALS */
694 if (cip->cin == NULL)
695 return (-1);
696 fd = fileno(cip->cin);
697#endif /* NO_SIGNALS */
698 if (fd < 0)
699 return (-1);
700 FD_ZERO(&ss);
701 FD_SET(fd, &ss);
702 tv.tv_sec = (unsigned long) sec;
703 tv.tv_usec = 0;
704 result = select(fd + 1, SELECT_TYPE_ARG234 &ss, NULL, NULL, &tv);
705 return (result);
706} /* WaitResponse */
#define fileno
Definition: acwin.h:102
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
Definition: select.c:41
#define ss
Definition: i386-dis.c:441
#define SELECT_TYPE_ARG234
Definition: wincfg.h:4
#define long
Definition: qsort.c:33
static int fd
Definition: io.c:51
Definition: winsock.h:66
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89

Referenced by FTPAbortDataTransfer().

Variable Documentation

◆ gLibNcFTP_Uses_Me_To_Quiet_Variable_Unused_Warnings

int gLibNcFTP_Uses_Me_To_Quiet_Variable_Unused_Warnings
extern

Definition at line 111 of file errno.c.

◆ gLibNcFTPVersion

char gLibNcFTPVersion[64]
extern

Definition at line 11 of file ftp.c.

Referenced by OpenControlConnection(), OpenTrace(), Usage(), and VersionCmd().