Making Downlod of WINDOWS directories

1

I have an application that transfers files via socket, however it is very tiring to have to make one-to-one transfers. My question is this:

How can I download a full DIRECTORY via socket?

The program works as follows, it prompts the user to enter the remote directory in which the file is to be downloaded, EXAMPLE: C: \ USERS \ ARCHIVE.DAT then it does a validation to confirm the existence of the file, and lastly it transfers the file byte to byte.

The problem is that when the user only passes the directory it fails validation, an example is if I type C: \ USERS \ DIRECTORY the program then returns a FAILED IN READ BYTES error

The solution would be to zip the directory, however the server only works with " SHELL " command lines, and Windows has nothing native to zip through the command line.

Any suggestions?

    
asked by anonymous 21.02.2015 / 00:22

1 answer

3

One option is to have this process applied to each file in the directory:

#include <dirent.h>

struct stat st;
lstat(caminho, &st);
if(S_ISDIR(st.st_mode)){
    //Se for diretório
    DIR *dir;
    struct dirent *ent;
    if ((dir = opendir (caminho)) != NULL) {
      // Abre o diretório
      while ((ent = readdir (dir)) != NULL) {
           //Passa por cada arquivo no diretório
           enviarArquivo(ent->d_name);
      }
      closedir (dir);
    } else {
      /* Erro abrindo diretório */
      perror ("");
      return EXIT_FAILURE;
    }
} else {
    //Se não for diretório
    enviarArquivo(caminho);
}

Adapted from:

link

link

    
21.02.2015 / 01:04