210
211
/* we have received data here */
213
size_t size = sizeof(struct sockaddr_in);
213
curl_socket_t s = CURL_SOCKET_BAD;
214
socklen_t size = (socklen_t) sizeof(struct sockaddr_in);
214
215
struct sockaddr_in add;
216
getsockname(sock, (struct sockaddr *) &add, (socklen_t *)&size);
217
s=accept(sock, (struct sockaddr *) &add, (socklen_t *)&size);
217
if(0 == getsockname(sock, (struct sockaddr *) &add, &size))
218
s=accept(sock, (struct sockaddr *) &add, &size);
219
220
sclose(sock); /* close the first socket */
1586
1583
return CURLE_FTP_WEIRD_227_FORMAT;
1589
snprintf(newhost, sizeof(newhost),
1590
"%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
1586
/* we got OK from server */
1587
if(data->set.ftp_skip_ip) {
1588
/* told to ignore the remotely given IP but instead use the one we used
1589
for the control connection */
1590
infof(data, "Skips %d.%d.%d.%d for data connection, uses %s instead\n",
1591
ip[0], ip[1], ip[2], ip[3],
1593
snprintf(newhost, sizeof(newhost), "%s", conn->ip_addr_str);
1596
snprintf(newhost, sizeof(newhost),
1597
"%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
1591
1598
newport = (port[0]<<8) + port[1];
1593
1600
else if(ftp->count1 == 0) {
1826
1830
CURLcode result = CURLE_OK;
1827
1831
struct SessionHandle *data=conn->data;
1829
if(ftpcode != 200) {
1833
if(ftpcode/100 != 2) {
1834
/* "sasserftpd" and "(u)r(x)bot ftpd" both responds with 226 after a
1835
successful 'TYPE I'. While that is not as RFC959 says, it is still a
1836
positive response code and we allow that. */
1830
1837
failf(data, "Couldn't set desired mode");
1831
1838
return CURLE_FTP_COULDNT_SET_BINARY; /* FIX */
1841
infof(data, "Got a %03d response code instead of the assumed 200\n",
1833
1844
if(instate == FTP_TYPE)
1834
1845
result = ftp_state_post_type(conn);
1835
1846
else if(instate == FTP_LIST_TYPE)
3654
3665
ftp = conn->proto.ftp;
3655
3666
ftp->ctl_valid = FALSE;
3658
ftp->diralloc = 5; /* default dir depth to allocate */
3659
ftp->dirs = (char **)calloc(ftp->diralloc, sizeof(ftp->dirs[0]));
3661
return CURLE_OUT_OF_MEMORY;
3663
/* parse the URL path into separate path components */
3664
while((slash_pos=strchr(cur_pos, '/'))) {
3665
/* 1 or 0 to indicate absolute directory */
3666
bool absolute_dir = (cur_pos - conn->path > 0) && (ftp->dirdepth == 0);
3668
/* seek out the next path component */
3669
if (slash_pos-cur_pos) {
3670
/* we skip empty path components, like "x//y" since the FTP command CWD
3671
requires a parameter and a non-existant parameter a) doesn't work on
3672
many servers and b) has no effect on the others. */
3673
int len = (int)(slash_pos - cur_pos + absolute_dir);
3674
ftp->dirs[ftp->dirdepth] = curl_unescape(cur_pos - absolute_dir, len);
3676
if (!ftp->dirs[ftp->dirdepth]) { /* run out of memory ... */
3677
failf(data, "no memory");
3679
return CURLE_OUT_OF_MEMORY;
3681
if (isBadFtpString(ftp->dirs[ftp->dirdepth])) {
3683
return CURLE_URL_MALFORMAT;
3687
cur_pos = slash_pos + 1; /* jump to the rest of the string */
3692
cur_pos = slash_pos + 1; /* jump to the rest of the string */
3693
if(++ftp->dirdepth >= ftp->diralloc) {
3696
ftp->diralloc *= 2; /* double the size each time */
3697
bigger = realloc(ftp->dirs, ftp->diralloc * sizeof(ftp->dirs[0]));
3668
switch(data->set.ftp_filemethod) {
3670
/* fastest, but less standard-compliant */
3671
ftp->file = conn->path; /* this is a full file path */
3674
case FTPFILE_SINGLECWD:
3675
/* get the last slash */
3676
slash_pos=strrchr(cur_pos, '/');
3678
ftp->dirdepth = 1; /* we consider it to be a single dir */
3679
ftp->dirs = (char **)calloc(1, sizeof(ftp->dirs[0]));
3681
return CURLE_OUT_OF_MEMORY;
3683
ftp->dirs[0] = curl_unescape(cur_pos, (int)(slash_pos-cur_pos));
3686
return CURLE_OUT_OF_MEMORY;
3688
ftp->file = slash_pos+1; /* the rest is the file name */
3691
ftp->file = cur_pos; /* this is a file name only */
3694
default: /* allow pretty much anything */
3695
case FTPFILE_MULTICWD:
3697
ftp->diralloc = 5; /* default dir depth to allocate */
3698
ftp->dirs = (char **)calloc(ftp->diralloc, sizeof(ftp->dirs[0]));
3700
return CURLE_OUT_OF_MEMORY;
3702
/* parse the URL path into separate path components */
3703
while((slash_pos=strchr(cur_pos, '/'))) {
3704
/* 1 or 0 to indicate absolute directory */
3705
bool absolute_dir = (cur_pos - conn->path > 0) && (ftp->dirdepth == 0);
3707
/* seek out the next path component */
3708
if (slash_pos-cur_pos) {
3709
/* we skip empty path components, like "x//y" since the FTP command CWD
3710
requires a parameter and a non-existant parameter a) doesn't work on
3711
many servers and b) has no effect on the others. */
3712
int len = (int)(slash_pos - cur_pos + absolute_dir);
3713
ftp->dirs[ftp->dirdepth] = curl_unescape(cur_pos - absolute_dir, len);
3715
if (!ftp->dirs[ftp->dirdepth]) { /* run out of memory ... */
3716
failf(data, "no memory");
3701
3718
return CURLE_OUT_OF_MEMORY;
3703
ftp->dirs = (char **)bigger;
3720
if (isBadFtpString(ftp->dirs[ftp->dirdepth])) {
3722
return CURLE_URL_MALFORMAT;
3726
cur_pos = slash_pos + 1; /* jump to the rest of the string */
3731
cur_pos = slash_pos + 1; /* jump to the rest of the string */
3732
if(++ftp->dirdepth >= ftp->diralloc) {
3735
ftp->diralloc *= 2; /* double the size each time */
3736
bigger = realloc(ftp->dirs, ftp->diralloc * sizeof(ftp->dirs[0]));
3740
return CURLE_OUT_OF_MEMORY;
3742
ftp->dirs = (char **)bigger;
3747
ftp->file = cur_pos; /* the rest is the file name */
3708
ftp->file = cur_pos; /* the rest is the file name */
3710
3750
if(*ftp->file) {
3711
3751
ftp->file = curl_unescape(ftp->file, 0);
3712
3752
if(NULL == ftp->file) {