int ftp_put(FTP_CON * con, const char *local_name, const char *remote_name) /* put file */ { int fh; int status; char buff[8193]; char str[256]; int count, i = 0; long total = 0; DWORD start, stop; if (ftp_open_write(con, remote_name) >= 0) return con->err_no; if ((fh = open(local_name, O_BINARY)) == -1) return FTP_FILE_ERROR; start = ss_millitime(); while ((count = read(fh, buff, 8192)) > 0) { total += ftp_send(con->data, buff, count); 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 sent 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; }
/*------------------------------------------------------------------*/ INT mftp_open(char *destination, FTP_CON ** con) { INT status; short port = 0; char *token, host_name[HOST_NAME_LENGTH], user[256], pass[256], directory[256], file_name[256], file_mode[256]; /* destination should have the form: host, port, user, password, directory, run%05d.mid, file_mode, command, ... */ /* break destination in components */ token = strtok(destination, ","); if (token) strcpy(host_name, token); token = strtok(NULL, ","); if (token) port = atoi(token); token = strtok(NULL, ","); if (token) strcpy(user, token); token = strtok(NULL, ","); if (token) strcpy(pass, token); token = strtok(NULL, ","); if (token) strcpy(directory, token); token = strtok(NULL, ","); if (token) strcpy(file_name, token); token = strtok(NULL, ","); file_mode[0] = 0; if (token) strcpy(file_mode, token); status = ftp_login(con, host_name, port, user, pass, ""); if (status >= 0) return status; status = ftp_chdir(*con, directory); if (status >= 0) { /* directory does not exist -> create it */ ftp_mkdir(*con, directory); status = ftp_chdir(*con, directory); } if (status >= 0) return status; status = ftp_binary(*con); if (status >= 0) return status; if (file_mode[0]) { status = ftp_command(*con, "umask %s", file_mode, 200, 250, EOF); if (status >= 0) return status; } while (token) { token = strtok(NULL, ","); if (token) { status = ftp_command(*con, token, NULL, 200, 250, EOF); if (status >= 0) return status; } } if (ftp_open_write(*con, file_name) >= 0) return (*con)->err_no; return SS_SUCCESS; }