How to access the particular directory using SFTP in C code I have never used SFTP. please help me in accessing the directory using SFTP in c language.
EDIT:
while ((dirp = readdir (directory)) != NULL) { 
  if ( strstr(dirp->d_name , ".txt" )) { 
    printf( "found a .txtfile: %s\n", dirp->d_name ); 
  } 
}


To access directory using SFTP, you can use ssh library function.
Here is some sample code, 
 do {
char mem[512];
char longentry[512];
LIBSSH2_SFTP_ATTRIBUTES attrs;

/* loop until we fail */ 
rc = libssh2_sftp_readdir_ex(sftp_handle, mem, sizeof(mem),

longentry, sizeof(longentry), &attrs);
if(rc > 0) {

if (longentry[0] != '\0') {
printf("%s\n", longentry);
} else {
if(attrs.flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) {
printf("--fix----- ");
}
else {
printf(" ");
}

if(attrs.flags & LIBSSH2_SFTP_ATTR_UIDGID) {
printf("%4ld %4ld ", attrs.uid, attrs.gid);
}
else {
printf("   -    - ");
}

if(attrs.flags & LIBSSH2_SFTP_ATTR_SIZE) {
printf("%8" PRIu64 " ", attrs.filesize);
}

printf("%s\n", mem);
}
}
else
break;

    } while (1);

For other api information, you can go through SFTP API documentation and give a try.
http://www.libssh2.org//libssh2_sftp_readdir_ex.html