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();
}
The code compiles well get executed but no file is uploaded any suggestions...