mirror of
https://github.com/sheumann/hush.git
synced 2025-01-18 07:31:34 +00:00
Allow recieving file to stdout, sending files from stdin, use the '-'
filename. Save a variable.
This commit is contained in:
parent
f62ea20aff
commit
236e93d133
@ -101,11 +101,9 @@ static FILE *ftp_login(ftp_host_info_t *server)
|
|||||||
{
|
{
|
||||||
FILE *control_stream;
|
FILE *control_stream;
|
||||||
char buf[512];
|
char buf[512];
|
||||||
int control_fd;
|
|
||||||
|
|
||||||
/* Connect to the command socket */
|
/* Connect to the command socket */
|
||||||
control_fd = xconnect(server->s_in);
|
control_stream = fdopen(xconnect(server->s_in), "r+");
|
||||||
control_stream = fdopen(control_fd, "r+");
|
|
||||||
if (control_stream == NULL) {
|
if (control_stream == NULL) {
|
||||||
bb_perror_msg_and_die("Couldnt open control stream");
|
bb_perror_msg_and_die("Couldnt open control stream");
|
||||||
}
|
}
|
||||||
@ -136,17 +134,12 @@ static FILE *ftp_login(ftp_host_info_t *server)
|
|||||||
static int ftp_recieve(ftp_host_info_t *server, FILE *control_stream,
|
static int ftp_recieve(ftp_host_info_t *server, FILE *control_stream,
|
||||||
const char *local_path, char *server_path)
|
const char *local_path, char *server_path)
|
||||||
{
|
{
|
||||||
char *filename;
|
|
||||||
char *local_file;
|
|
||||||
char buf[512];
|
char buf[512];
|
||||||
off_t filesize = 0;
|
off_t filesize = 0;
|
||||||
int fd_data;
|
int fd_data;
|
||||||
int fd_local;
|
int fd_local = -1;
|
||||||
off_t beg_range = 0;
|
off_t beg_range = 0;
|
||||||
|
|
||||||
filename = bb_get_last_path_component(server_path);
|
|
||||||
local_file = concat_path_file(local_path, filename);
|
|
||||||
|
|
||||||
/* Connect to the data socket */
|
/* Connect to the data socket */
|
||||||
if (ftpcmd("PASV", NULL, control_stream, buf) != 227) {
|
if (ftpcmd("PASV", NULL, control_stream, buf) != 227) {
|
||||||
bb_error_msg_and_die("PASV error: %s", buf + 4);
|
bb_error_msg_and_die("PASV error: %s", buf + 4);
|
||||||
@ -157,9 +150,14 @@ static int ftp_recieve(ftp_host_info_t *server, FILE *control_stream,
|
|||||||
filesize = atol(buf + 4);
|
filesize = atol(buf + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((local_path[0] == '-') && (local_path[1] == '\0')) {
|
||||||
|
fd_local = fileno(stdout);
|
||||||
|
do_continue = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (do_continue) {
|
if (do_continue) {
|
||||||
struct stat sbuf;
|
struct stat sbuf;
|
||||||
if (lstat(local_file, &sbuf) < 0) {
|
if (lstat(local_path, &sbuf) < 0) {
|
||||||
bb_perror_msg_and_die("fstat()");
|
bb_perror_msg_and_die("fstat()");
|
||||||
}
|
}
|
||||||
if (sbuf.st_size > 0) {
|
if (sbuf.st_size > 0) {
|
||||||
@ -183,10 +181,12 @@ static int ftp_recieve(ftp_host_info_t *server, FILE *control_stream,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* only make a local file if we know that one exists on the remote server */
|
/* only make a local file if we know that one exists on the remote server */
|
||||||
if (do_continue) {
|
if (fd_local == -1) {
|
||||||
fd_local = bb_xopen(local_file, O_APPEND | O_WRONLY);
|
if (do_continue) {
|
||||||
} else {
|
fd_local = bb_xopen(local_path, O_APPEND | O_WRONLY);
|
||||||
fd_local = bb_xopen(local_file, O_CREAT | O_TRUNC | O_WRONLY);
|
} else {
|
||||||
|
fd_local = bb_xopen(local_path, O_CREAT | O_TRUNC | O_WRONLY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy the file */
|
/* Copy the file */
|
||||||
@ -226,21 +226,24 @@ static int ftp_send(ftp_host_info_t *server, FILE *control_stream,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* get the local file */
|
/* get the local file */
|
||||||
fd_local = bb_xopen(local_path, O_RDONLY);
|
if ((local_path[0] == '-') && (local_path[1] == '\0')) {
|
||||||
fstat(fd_local, &sbuf);
|
fd_local = fileno(stdin);
|
||||||
|
} else {
|
||||||
|
fd_local = bb_xopen(local_path, O_RDONLY);
|
||||||
|
fstat(fd_local, &sbuf);
|
||||||
|
|
||||||
sprintf(buf, "ALLO %lu", (unsigned long)sbuf.st_size);
|
sprintf(buf, "ALLO %lu", (unsigned long)sbuf.st_size);
|
||||||
response = ftpcmd(buf, NULL, control_stream, buf);
|
response = ftpcmd(buf, NULL, control_stream, buf);
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case 200:
|
case 200:
|
||||||
case 202:
|
case 202:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
close(fd_local);
|
close(fd_local);
|
||||||
bb_error_msg_and_die("ALLO error: %s", buf + 4);
|
bb_error_msg_and_die("ALLO error: %s", buf + 4);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
response = ftpcmd("STOR ", local_path, control_stream, buf);
|
response = ftpcmd("STOR ", local_path, control_stream, buf);
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case 125:
|
case 125:
|
||||||
@ -328,6 +331,12 @@ int ftpgetput_main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
bb_applet_long_options = ftpgetput_long_options;
|
bb_applet_long_options = ftpgetput_long_options;
|
||||||
opt = bb_getopt_ulflags(argc, argv, "cvu:p:P:", &server->user, &server->password, &port);
|
opt = bb_getopt_ulflags(argc, argv, "cvu:p:P:", &server->user, &server->password, &port);
|
||||||
|
|
||||||
|
/* Process the non-option command line arguments */
|
||||||
|
if (argc - optind != 3) {
|
||||||
|
bb_show_usage();
|
||||||
|
}
|
||||||
|
|
||||||
if (opt & FTPGETPUT_OPT_CONTINUE) {
|
if (opt & FTPGETPUT_OPT_CONTINUE) {
|
||||||
do_continue = 1;
|
do_continue = 1;
|
||||||
}
|
}
|
||||||
@ -335,13 +344,6 @@ int ftpgetput_main(int argc, char **argv)
|
|||||||
verbose_flag = 1;
|
verbose_flag = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Process the non-option command line arguments
|
|
||||||
*/
|
|
||||||
if (argc - optind != 3) {
|
|
||||||
bb_show_usage();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* We want to do exactly _one_ DNS lookup, since some
|
/* We want to do exactly _one_ DNS lookup, since some
|
||||||
* sites (i.e. ftp.us.debian.org) use round-robin DNS
|
* sites (i.e. ftp.us.debian.org) use round-robin DNS
|
||||||
* and we want to connect to only one IP... */
|
* and we want to connect to only one IP... */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user