Back to product page

LoopItem callback


Called before wodSFTP performs operation on item from the GetFiles/PutFiles/DeleteFiles/LoopFiles sequence.

Syntax

  • C
void (*LoopItem)(void *Sftp, char *LocalFile, char *RemoteFile, DirItemTypes ItemType, int *Skip);
The LoopItem(void *Sftp,char *LocalFile,char *RemoteFile,DirItemTypes ItemType,int *Skip) syntax has these parts:
void *SftpHandle of the created Sftp instance.
char *LocalFileHolds full path to file/folder on local disk
char *RemoteFileHolds full path to file/folder on remote server.
DirItemTypes ItemTypeA DirItemTypes enumeration. Type of the item - file, folder, symbolic link.
int *SkipWhen set to 0 (null, false), wodSFTP continues with operation on specified file. Otherwise, file is skipped.

Remarks

The LoopItem callback will be called as a result of the GetFiles, PutFiles, DeleteFiles and LoopFiles functions. TIt provides information about each item in the sequence (meaning file or folder) before actual operation on that item is executed - allowing you to optionally Skip the operation for this particular item.

Since both LocalFile and RemoteFile arguments can be changed, you can also cause operation to be performed on completely different files than it would be in original operation. LocalFile and RemoteFile point to 32k buffer that you can overwrite with new file/folder path.

For example, you can use LoopItem callback like this:
 
void SftpLoopItem(void *Sftp, char *LocalFile, char *RemoteFile, DirItemTypes ItemType, int *Skip)
{
  if (ItemType == typeDirectory)
  *Skip = FALSE;
  else
  {
     int i = strlen(RemoteFile);
     if (i>4)
     {
        if (!strcmp(&RemoteFile[i-4], ".txt"))
        {
           *Skip = FALSE;
           return;
        }
     }
     *Skip = TRUE;
  }
}
 

which means that only files ending with ".txt" are copied - others are skipped (but directories are created, just in case).

You can also use it like this: we will copy all ".txt" files to the same directory, no matter where they originate from:
 
void SftpLoopItem(void *Sftp, char *LocalFile, char *RemoteFile, DirItemTypes ItemType, int *Skip)
{
  int i = strlen(RemoteFile);
  if (i>4)
  {
     if (!strcmp(&RemoteFile[i-4], ".txt"))
     {
        char buff[MAX_PATH];
        sprintf(buff, "c:\\mytxtfiles\\file%d.txt", mycounter++);
        strcpy(LocalFile, buff);
        *Skip = FALSE;
        return;
     }
  }
  *Skip = TRUE;
}
 

above sample will not create directory structure at all - but still would copy all .txt files to differently named files on local disk.

NOTE: this callback is called only if you have created an instance of the SftpEventsStruct structure, and set its LoopItem member to the function implementing it.

Platforms

Windows