|
|||||||||||
|
sftp - reput, reget
From: Dmitry Lohansky <sq(at)oganer.net>
Date: Sat Sep 13 2003 - 06:27:53 EDT I would like to give my patches for sftp-client. I have added -c option for get/put commands, whith it 'get' will download file restarting at the end of local file (like ftp's 'reget' command). Similar for 'put'. Modified files are: sftp-client.c, sftp-int.c, sftp-int.h For the future.. is it tech@ or misc@ stuff?
extern int showprogress;
Attrib junk, *a;
char *handle;
int local_fd, status, num_req, max_req, write_error;
- int read_error, write_errno;
+ int read_error, write_errno, open_flags;
u_int64_t offset, size;
u_int handle_len, mode, type, id, buflen;
off_t progress_counter;
+ struct stat sb;
struct request {
u_int id;
@@ -945,8 +960,8 @@
/* Override umask and utimes if asked */
- if (pflag && fchmod(local_fd, mode) == -1)
+ if ((pgflags & PG_PERM) && fchmod(local_fd, mode) == -1)
error("Couldn't set mode on \"%s\": %s", local_path,
strerror(errno));
- if (pflag && (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME)) {
+ if ((pgflags & PG_PERM) && (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME)) {
struct timeval tv[2];
tv[0].tv_sec = a->atime;
@@ -967,7 +982,7 @@ int do_upload(struct sftp_conn *conn, char *local_path, char *remote_path, - int pflag) + int pgflags) { - int local_fd, status; + int local_fd, status, open_flags; u_int handle_len, id, type; u_int64_t offset; @@ -1026,5 +1045,5 @@
buffer_clear(&msg);
handle = get_handle(conn->fd_in, id, &handle_len);
if (handle == NULL) {
@@ -1038,5 +1072,4 @@ /* Read from local and write to remote */ - offset = 0; if (showprogress) start_progress_meter(local_path, sb.st_size, &offset); @@ -1135,5 +1168,5 @@ /* Override umask and utimes if asked */ - if (pflag) + if (pgflags & PG_PERM) do_fsetstat(conn, handle, handle_len, &a); --- sftp-int.c.orig Mon Aug 25 16:13:09 2003 +++ sftp-int.c Sat Sep 13 18:07:00 2003 @@ -282,5 +282,5 @@
static int
const char *cp = *cpp;
/* Check for flags */
- if (cp[0] == '-' && cp[1] && strchr(WHITESPACE, cp[2])) {
- switch (cp[1]) {
- case 'p':
- case 'P':
- *pflag = 1;
- break;
- default:
- error("Invalid flag -%c", cp[1]);
- return(-1);
- }
- cp += 2;
- *cpp = cp + strspn(cp, WHITESPACE);
+ while (cp[0] == '-') {
+ cp++;
+ while (cp[0] && !strchr(WHITESPACE, cp[0]))
+ switch (cp[0]) {
+ case 'p':
+ case 'P':
+ *pgflags += PG_PERM;
+ cp++;
+ break;
+ case 'c':
+ case 'C':
+ *pgflags += PG_CONT;
+ cp++;
+ break;
+ default:
+ error("Invalid flag -%c", cp[0]);
+ return(-1);
+ }
+ cp += strspn(cp, WHITESPACE);
}
+
+ *cpp = cp;
return(0);
@@ -432,5 +441,5 @@
static int
char *abs_src = NULL;
printf("Fetching %s to %s\n", g.gl_pathv[i], abs_dst);
- if (do_download(conn, g.gl_pathv[i], abs_dst, pflag) == -1)
+ if (do_download(conn, g.gl_pathv[i], abs_dst, pgflags) == -1)
err = -1;
xfree(abs_dst);
@@ -499,5 +508,5 @@
static int
char *tmp_dst = NULL;
printf("Uploading %s to %s\n", g.gl_pathv[i], abs_dst);
- if (do_upload(conn, g.gl_pathv[i], abs_dst, pflag) == -1)
+ if (do_upload(conn, g.gl_pathv[i], abs_dst, pgflags) == -1)
err = -1;
}
@@ -738,5 +747,5 @@
static int
unsigned long *n_arg, char **path1, char **path2)
{
/* Get arguments and parse flags */
- *lflag = *pflag = *n_arg = 0;
+ *lflag = *pgflags = *n_arg = 0;
*path1 = *path2 = NULL;
switch (cmdnum) {
@@ -897,5 +906,5 @@ { char *path1, *path2, *tmp; - int pflag, lflag, iflag, cmdnum, i; + int pgflags, lflag, iflag, cmdnum, i; unsigned long n_arg; Attrib a, *aa; @@ -905,5 +914,5 @@ path1 = path2 = NULL; - cmdnum = parse_args(&cmd, &pflag, &lflag, &iflag, &n_arg, + cmdnum = parse_args(&cmd, &pgflags, &lflag, &iflag, &n_arg, &path1, &path2); @@ -25,3 +25,11 @@ */ +#ifndef _SFTP_INT_H +#define _SFTP_INT_H + +#define PG_PERM 1 +#define PG_CONT 2 + int interactive_loop(int, int, char *, char *);+ +#endif /* _SFTP_INT_H */ Received on Sat Sep 13 06:34:34 2003 This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 13:48:44 EDT |
||||||||||
|
|||||||||||