Downloding of WINDOWS directories

Asked

Viewed 52 times

1

I have an application that transfers files via socket, but it is very tiring to have to make transfers from one to one. My question is the following:

How can I download a DIRECTORY complete via socket?

The program works as follows, it asks the user to enter the remote directory in which the file is for transfer, EXAMPLE: C: USERS.DAT FILE then it does a validation to confirm the existence of the file, and lastly it transfers the file byte by byte.

The problem is that when the user only passes the directory he fails to validate, an example is if I type C: USERS DIRECTORY the program then returns an error of FAILED IN READ BYTES

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

Any suggestions?

1 answer

3

One option for this 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:

https://stackoverflow.com/questions/3536781/accessing-directories-in-c/3536853#3536853

https://stackoverflow.com/questions/612097/how-can-i-get-the-list-of-files-in-a-directory-using-c-or-c

Browser other questions tagged

You are not signed in. Login or sign up in order to post.