Esempio n. 1
0
void cmd_cat(int argc, char **argv)
{
	int i;
	struct option longopts[] = {
		{"type", required_argument, 0, 't'},
		{"help", no_argument, 0, 'h'},
		{0, 0, 0, 0}
	};
	int c;
	transfer_mode_t mode = tmAscii;

	optind = 0;
	while((c = getopt_long(argc, argv, "t:h", longopts, 0)) != EOF) {
		switch(c) {
		case 't':
			if(strncmp(optarg, "ascii", strlen(optarg)) == 0)
				mode = tmAscii;
			else if(strncmp(optarg, "binary", strlen(optarg)) == 0)
				mode = tmBinary;
			else {
				fprintf(stderr,
						_("Invalid option argument --type=%s\n"), optarg);
				return;
			}
			break;
		case 'h':
			fprintf(stderr, "Print file(s) on standard output.  Usage:\n"
					"  cat [options] <file>...\n"
					"Options:\n"
					"  -t, --type=TYPE    set transfer TYPE to ascii"
					" or binary\n"
					"  -h, --help         show this help\n");
			return;
		case '?':
			optind = -1;
			return;
		}
	}

	minargs(optind);
	need_connected();
	need_loggedin();

	for(i = optind; i < argc; i++) {
		listitem *gli;
		list *gl = rglob_create();
		stripslash(argv[i]);
		if(rglob_glob(gl, argv[i], true, false, 0) == -1)
			fprintf(stderr, _("%s: no matches found\n"), argv[i]);
		for(gli = gl->first; gli; gli=gli->next) {
			rfile *rf = (rfile *)gli->data;
			const char *fn = base_name_ptr(rf->path);
			if(strcmp(fn, ".") != 0 && strcmp(fn, "..") != 0) {
				ftp_receive(rf->path, stdout, mode, 0);
				fflush(stdout);
			}
		}
		rglob_destroy(gl);
	}
}
Esempio n. 2
0
int main()
{
    /* content-length of the file */
    unsigned opt;
    const char *port = "ftp";
    ftp_host_info_t *server;
    /* socket to ftp server */
    FILE *control_stream;
    static FILE ctrl_stream;
    /* continue previous transfer (-c) */
    char caFtpHead[FTP_HEAD_SIZE];
    int nFileSize;
    int rd = 0;
    int nFdData;
    int nSave;
    char *pcRam;

    //FILE* ftp_get_head(const char *host, int port, const char *user, const char *password, char *server_path,
    //          char caFtpHead[FTP_HEAD_SIZE], int *pnHeadSize, int *pnFdData, FILE *ctrl_stream, int *pnFileSize)
    control_stream = ftp_get_head("192.168.1.170", 21, "sun", "123456", "sip11.cfg",
                                  caFtpHead, &rd, &nFdData, &ctrl_stream, &nFileSize);
    caFtpHead[rd - 1] = '\0';
    printf("-------rd=%d===nFileSize=%d===\n", rd, nFileSize);
    printf("-------------------------n %s n------------------------\n", caFtpHead);

    //nSave = ftp_recv_to_file(nFdData, control_stream, caFtpHead, rd, "test.cfg");
    pcRam = (char *)calloc(sizeof(char), nFileSize);
    if (NULL == pcRam) {
        perror("calloc error\n");
        exit(-1);
    }

    nSave = ftp_recv_to_ram(nFdData, control_stream, caFtpHead, rd, pcRam);
    printf("nSave =%d \n", nSave);
    pcRam[200] = '\0';
    printf("-------------------------n %s n------------------------\n", pcRam + 130000);
    return 0;


    /* Set default values */
    server = xmalloc(sizeof(*server));
    server->user = "******";
    server->password = "******";

    /* We want to do exactly _one_ DNS lookup, since some sites (i.e. ftp.us.debian.org) use round-robin DNS
     * and we want to connect to only one IP... */
    server->lsa = str2sockaddr("192.168.1.151", 21, DIE_ON_ERROR);
    printf("BUFSIZ=%d  off_t = %d\n", BUFSIZ, (int)((off_t) - 1));

    /* Connect/Setup/Configure the FTP session */
    control_stream = ftp_login(server);
    ftp_receive(server, control_stream, "ram.bin", "ram_zimage.bin");
    return 0;
}
Esempio n. 3
0
File: ftplib.c Progetto: cjpl/midas
int ftp_dir(FTP_CON * con, const char *file)
/* display directory */
{
   char command[256], buffer[8192];

   if (file == NULL || *file == '\0')
      strcpy(command, "LIST");
   else
      sprintf(command, "LIST %s", file);

   if (ftp_data(con, command, "") >= 0)
      return con->err_no;

   while (ftp_receive(con->data, buffer, sizeof(buffer)))
      printf("%s", buffer);

   return ftp_close(con);
}
Esempio n. 4
0
File: ftplib.c Progetto: cjpl/midas
int ftp_get(FTP_CON * con, const char *local_name, const char *remote_name)
/* get file */
{
   int fh;
   int status;
   char buff[8192];
   char str[256];
   int count, i;
   long total = 0;
   DWORD start, stop;

   if (ftp_open_read(con, remote_name) >= 0)
      return con->err_no;

   if ((fh = open(local_name, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0644)) == -1)
      return FTP_FILE_ERROR;

   start = ss_millitime();

   while ((count = ftp_receive(con->data, buff, sizeof(buff))) > 0) {
      total += write(fh, buff, count);
      i = 0;
      if (ftp_debug_func != NULL) {
         printf("%c\r", bars[(i++) % 4]);
         fflush(stdout);
      }
   }

   close(fh);
   stop = ss_millitime();

   status = ftp_close(con);
   if (ftp_debug_func != NULL) {
      sprintf(str, "%ld bytes received in %1.2f seconds (%1.2lf kB/sec).",
              total, (stop - start) / 1000.0, total / 1024.0 / ((stop - start) / 1000.0));
      ftp_debug_func(str);
   }

   return status;
}