summaryrefslogtreecommitdiff
path: root/utils/ftpcp.c
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1997-08-08 23:52:25 +0000
committerMiles Bader <miles@gnu.org>1997-08-08 23:52:25 +0000
commite729b30fb46c40b6026e1c69c7922d5114db07c7 (patch)
tree673621a88bfd6e4608ad643d56f0b54a6f455c6d /utils/ftpcp.c
parent802819fbf43a648a72f5437036aab3a0b5efb822 (diff)
(append_basename):
New function. (main): Move target directory handling to append_basename. Use it also with remote transfers.
Diffstat (limited to 'utils/ftpcp.c')
-rw-r--r--utils/ftpcp.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/utils/ftpcp.c b/utils/ftpcp.c
index 4bb27333..3782335f 100644
--- a/utils/ftpcp.c
+++ b/utils/ftpcp.c
@@ -283,6 +283,24 @@ ebasename (struct epoint *e, const char *composite, char **base)
}
}
+static void
+append_basename (struct epoint *dst, struct epoint *src)
+{
+ char *bname;
+ error_t err = ebasename (src, src->file, &bname);
+
+ if (err)
+ error (33, err, "%s: Cannot find basename", src->name);
+
+ err = eappend (dst, dst->file, bname, &dst->file);
+ if (err)
+ error (34, err, "%s: Cannot append name component", dst->name);
+
+ err = eappend (dst, dst->name, bname, &dst->name);
+ if (err)
+ error (35, err, "%s: Cannot append name component", dst->name);
+}
+
int
main (int argc, char **argv)
{
@@ -335,6 +353,13 @@ main (int argc, char **argv)
if (rd.conn && wr.conn)
{
err = ftp_conn_rmt_copy (rd.conn, rd.file, wr.conn, wr.file);
+ if (err == EISDIR)
+ /* The destination name is a directory; try again with the source
+ basename appended. */
+ {
+ append_basename (&wr, &rd);
+ err = ftp_conn_rmt_copy (rd.conn, rd.file, wr.conn, wr.file);
+ }
if (err)
error (30, err, "Remote copy");
}
@@ -351,19 +376,7 @@ main (int argc, char **argv)
/* The destination name is a directory; try again with the source
basename appended. */
{
- char *bname;
-
- err = ebasename (&rd, rd.file, &bname);
- if (err)
- error (33, err, "%s: Cannot find basename", rd.name);
-
- err = eappend (&wr, wr.file, bname, &wr.file);
- if (err)
- error (34, err, "%s: Cannot append name component", wr.name);
- err = eappend (&wr, wr.name, bname, &wr.name);
- if (err)
- error (35, err, "%s: Cannot append name component", wr.name);
-
+ append_basename (&wr, &rd);
err = eopen_wr (&wr, &wr_fd);
}
if (err)