2 * Copyright (c) 2000, Red Hat, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
12 * Written by DJ Delorie <dj@cygnus.com>
16 /* This file is responsible for implementing all direct FTP protocol
17 channels. It is intentionally simplistic. */
33 static SimpleSocket *cmd = 0;
34 static char *cmd_host = 0;
35 static int cmd_port = 0;
37 static char *last_line;
40 ftp_line (SimpleSocket *s)
43 last_line = s->gets ();
44 log (LOG_BABBLE, "ftp > %s", last_line);
45 } while (last_line && (!isdigit (last_line[0]) || last_line[3] != ' '));
46 return atoi (last_line ?: "0");
49 NetIO_FTP::NetIO_FTP (char *Purl)
58 if (cmd_host && strcmp (host, cmd_host) != 0 || port != cmd_port)
61 cmd->printf ("QUIT\r\n");
70 SimpleSocket *c = new SimpleSocket (host, port);
72 c->printf ("USER anonymous\r\n");
76 c->printf ("PASS xemacs-setup@\r\n");
80 if (code < 200 || code >= 300)
87 cmd_host = _strdup (host);
90 cmd->printf ("TYPE I\r\n");
91 code = ftp_line (cmd);
94 cmd->printf ("PASV\r\n");
96 code = ftp_line (cmd);
97 } while (code == 226); /* previous RETR */
101 char *paren = strchr (last_line, '(');
105 int i1, i2, i3, i4, p1, p2;
106 sscanf (paren+1, "%d,%d,%d,%d,%d,%d", &i1, &i2, &i3, &i4, &p1, &p2);
108 sprintf (tmp, "%d.%d.%d.%d", i1, i2, i3, i4);
109 s = new SimpleSocket (tmp, p1*256 + p2);
111 cmd->printf ("RETR %s\r\n", path);
112 code = ftp_line (cmd);
121 NetIO_FTP::~NetIO_FTP ()
136 NetIO_FTP::read (char *buf, int nbytes)
140 return s->read (buf, nbytes);