]>
cygwin.com Git - cygwin-apps/setup.git/blob - nio-ftp.cc
2 * Copyright (c) 2000, 2001, 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. */
21 #include "LogSingleton.h"
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
)
44 last_line
= s
->gets ();
45 Log (LOG_BABBLE
) << "ftp > " << (last_line
? last_line
: "error")
48 while (last_line
&& (!isdigit (last_line
[0]) || last_line
[3] != ' '));
49 return atoi (last_line
? : "0");
52 NetIO_FTP::NetIO_FTP (char const *Purl
):NetIO (Purl
)
62 if ((cmd_host
&& strcmp (host
, cmd_host
) != 0) || port
!= cmd_port
)
65 cmd
->printf ("QUIT\r\n");
75 c
= new SimpleSocket (host
, port
);
80 c
->printf ("USER %s\r\n", net_ftp_user
);
82 c
->printf ("USER anonymous\r\n");
87 c
->printf ("PASS %s\r\n", net_ftp_passwd
);
89 c
->printf ("PASS cygwin-setup@\r\n");
92 if (code
== 530) /* Authentication failed, retry */
95 if (net_ftp_user
&& net_ftp_passwd
)
99 if (code
< 200 || code
>= 300)
107 cmd_host
= new char [strlen (host
) + 1];
108 strcpy (cmd_host
, host
);
111 cmd
->printf ("TYPE I\r\n");
112 code
= ftp_line (cmd
);
115 cmd
->printf ("PASV\r\n");
118 code
= ftp_line (cmd
);
120 while (code
== 226); /* previous RETR */
121 if (code
== 421) /* Timeout, retry */
123 Log (LOG_BABBLE
) << "FTP timeout -- reconnecting" << endLog
;
125 cmd_host
= new char[1]; cmd_host
[0] = '\0';
126 goto control_reconnect
;
132 digit
= strpbrk (last_line
+ 3, "0123456789");
137 i1
, i2
, i3
, i4
, p1
, p2
;
138 sscanf (digit
, "%d,%d,%d,%d,%d,%d", &i1
, &i2
, &i3
, &i4
, &p1
, &p2
);
141 sprintf (tmp
, "%d.%d.%d.%d", i1
, i2
, i3
, i4
);
142 s
= new SimpleSocket (tmp
, p1
* 256 + p2
);
144 cmd
->printf ("RETR %s\r\n", path
);
145 code
= ftp_line (cmd
);
146 if (code
!= 150 && code
!= 125)
155 NetIO_FTP::~NetIO_FTP ()
170 NetIO_FTP::read (char *buf
, int nbytes
)
175 rv
= s
->read (buf
, nbytes
);
This page took 0.044781 seconds and 5 git commands to generate.