![]() |
| | #1 |
| Registered User Join Date: Oct 2009
Posts: 2
| ftp connection error Code: #include <windows.h>
#include <stdio.h>
WSADATA ws;
int d;
char aa[1000];
char usr[100];
char paswd[100];
struct sockaddr_in a;
SOCKET s;
int ii;
struct hostent *host;
void abc(char *p)
{
FILE *fp = fopen("b.txt","a+");
fprintf(fp,"%s\n",p);
fclose(fp);
}
_stdcall WinMain(HINSTANCE i, HINSTANCE j, char *k, int l)
{
d = WSAStartup(0x101,&ws);
sprintf(aa," WSASTARTUP = %d",d);
abc(aa);
s = socket(AF_INET,SOCK_STREAM,0);
sprintf(aa," SOCKET = %d",s);
abc(aa);
host=gethostbyname("smartfile.com");
a.sin_family = AF_INET;
a.sin_port = htons(21);
a.sin_addr.s_addr = *((unsigned long*)host->h_addr);
d = connect(s, (struct sockaddr *)&a, sizeof( a));
strcat(usr,"USER xyzab\r\n");
send(s,usr,sizeof(usr),0);
ii = 1;
ii = recv(s,aa,1000,0);
abc(aa);
strcat(paswd,"PASS abcdeg\r\n");
send(s,paswd,sizeof(paswd),0);
ii = 1;
ii = recv(s,aa,1000,0);
abc(aa);
}
: WSASTARTUP = 0 SOCKET = 1940 220 208.88.252.31 FTP server ready 331 Password required for illusionist 500 Invalid command: try being more creative rd required for illusionist I can't figure out why password command give error plz help..... |
| illusionist is offline | |
| | #2 |
| Registered User Join Date: Sep 2004 Location: California
Posts: 2,845
| You are sending garbage to the server: Code: strcat(usr,"USER xyzab\r\n"); send(s,usr,sizeof(usr),0); "USER xyzab\r\n\0<random garbage here>" Instead of sending the entire buffer, you need to just send the string: Code: send(s,usr,strlen(usr),0);
__________________ bit∙hub [bit-huhb] n. A source and destination for information. |
| bithub is offline | |
| | #3 |
| Registered User Join Date: Oct 2009
Posts: 2
| Thanx it worked now i have completed code to upload a text file to server code for that is: Code: #include <windows.h>
#include <stdio.h>
WSADATA ws;
int d;
char aa[1000];
char usr[100];
char paswd[100]={0};
char cmd[15]={0};
struct sockaddr_in a;
struct sockaddr_in a1;
SOCKET s;
SOCKET s1;
int ii;
struct hostent *host;
int calcp(char p1[])
{
int i,k;
int n;
char port1[10];
char port2[10];
int por;
i=k=n=por=0;
while(p1[i] != '(' )
i++;
n=0;
while( n < 4 )
{
if( p1[i] == ',')
n++;
i++;
}
k=0;
while(p1[i] != ',' )
{
port1[k++]=p1[i];
i++;
}
i++;
port1[k]='\0';
k=0;
while(p1[i] != ')' )
{
port2[k++]=p1[i];
i++;
}
port2[k++]='\0';
k=0;
por= atoi(port1)*256 + atoi(port2);
}
void abc(char *p)
{
FILE *fp = fopen("b.txt","a+");
fprintf(fp,"%s\n",p);
fclose(fp);
}
_stdcall WinMain(HINSTANCE i, HINSTANCE j, char *k, int l)
{
int port=0;
d = WSAStartup(0x101,&ws);
sprintf(aa," WSASTARTUP = %d",d);
abc(aa);
s = socket(AF_INET,SOCK_STREAM,0);
sprintf(aa," SOCKET = %d",s);
abc(aa);
host=gethostbyname("smartfile.com");
a.sin_family = AF_INET;
a.sin_port = htons(21);
a.sin_addr.s_addr = *((unsigned long*)host->h_addr);
d = connect(s, (struct sockaddr *)&a, sizeof( a));
strcpy(usr,"USER xxxxxxx\r\n");
send(s,usr,strlen(usr),0);
sleep(1000);
ii = 1;
ii = recv(s,aa,1000,0);
abc(aa);
strcpy(paswd,"PASS xxxxxx\r\n");
send(s,paswd,strlen(paswd),0);
sleep(1000);
ii = 1;
ii = recv(s,aa,1000,0);
abc(aa);
send(s,"TYPE I\r\n",8,0);
sleep(1000);
ii = 1;
ii = recv(s,aa,1000,0);
abc(aa);
send(s,"PASV\r\n",6,0);
sleep(1000);
ii = 1;
ii = recv(s,aa,1000,0);
abc(aa);
port=calcp(aa);
s1 = socket(AF_INET,SOCK_STREAM,0);
sprintf(aa," SOCKET = %d",s1);
abc(aa);
a1.sin_family = AF_INET;
a1.sin_port = htons(port);
a1.sin_addr.s_addr = *((unsigned long*)host->h_addr);
d = connect(s1, (struct sockaddr *)&a1, sizeof( a1));
strcpy(cmd,"STOR /b.txt\r\n");
send(s1,cmd,strlen(cmd),0);
sleep(1000);
WSACleanup();
}
Plz |
| illusionist is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem defining structure | MTK | C Programming | 12 | 09-08-2009 03:26 PM |
| Testing some code, lots of errors... | Sparrowhawk | C Programming | 48 | 12-15-2008 04:09 AM |
| Another syntax error | caldeira | C Programming | 31 | 09-05-2008 01:01 AM |
| Dikumud | maxorator | C++ Programming | 1 | 10-01-2005 06:39 AM |
| Problem with Visual C++ Object-Oriented Programming Book. | GameGenie | C++ Programming | 9 | 08-29-2005 11:21 PM |