Click here to Skip to main content
15,888,984 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Passing pointers to function into another function Pin
David Crow1-Nov-07 12:13
David Crow1-Nov-07 12:13 
GeneralRe: Passing pointers to function into another function Pin
acerunner3161-Nov-07 12:22
acerunner3161-Nov-07 12:22 
GeneralRe: Passing pointers to function into another function Pin
David Crow2-Nov-07 2:43
David Crow2-Nov-07 2:43 
AnswerRe: Passing pointers to function into another function Pin
Mark Salsbery1-Nov-07 11:04
Mark Salsbery1-Nov-07 11:04 
AnswerRe: Passing pointers to function into another function Pin
Randor 1-Nov-07 11:44
professional Randor 1-Nov-07 11:44 
GeneralRe: Passing pointers to function into another function [modified] Pin
acerunner3161-Nov-07 12:06
acerunner3161-Nov-07 12:06 
AnswerRe: Passing pointers to function into another function [modified] Pin
Stephen Hewitt1-Nov-07 14:35
Stephen Hewitt1-Nov-07 14:35 
QuestionSimple FTP Client Pin
dellthinker1-Nov-07 9:26
dellthinker1-Nov-07 9:26 
Hi all. Im trying to make a simple FTP client that uploads files. Again im trying to make a client that uploads files and not downloads. I specified that so that we could get an understanding of what im trying to do here. Anyway i was refered to a site that deals with programming for FTP Servers. Heres the url: http://www.stanford.edu/class/ee284/pa.html

he instructions were written for a UNIX programming but WinSock supports all the functions it calls for. The functions are the following:

socket()
bind()
listen()
getsockname()
accept()

Mind everyone finding a simple way to use these functions is NOT a simple task. But after spending countless hours using google/yahoo i came up with the following code:

<br />
#include <iostream><br />
#include <winsock.h><br />
using namespace std;<br />
<br />
<br />
#define port 21<br />
bool ftpmsg(const char *message);<br />
SOCKET dataSock;<br />
SOCKET socketbuffer;<br />
<br />
int main(){<br />
    const int SIZE=100;<br />
    char msg[SIZE];<br />
    char server[SIZE];<br />
    char recvbuffer[900];<br />
    WORD wVersionRequested;<br />
    SOCKADDR_IN addr;<br />
    WSADATA wsa;<br />
    struct sockaddr_in    structSock;<br />
    struct hostent *ftpserveraddy;<br />
    wVersionRequested=MAKEWORD(2, 0);<br />
    WSAStartup(wVersionRequested, &wsa);<br />
    dataSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);<br />
   <br />
    printf("Please enter the Host name to connect to:");<br />
    cin.getline(server, SIZE);<br />
    printf("Connecting to FTP Server: '%s'\n",server);<br />
    if((ftpserveraddy = gethostbyname(server)) == NULL){<br />
        printf("DNS Lookup of '%s' failed!\n",msg);<br />
    }<br />
    structSock.sin_family = AF_INET;  <br />
    structSock.sin_port = htons(port);<br />
    structSock.sin_addr.s_addr = *((unsigned long*)ftpserveraddy->h_addr_list[0]);<br />
    memset(structSock.sin_zero, 0, 8);<br />
    if(connect(dataSock, (sockaddr*)&structSock, sizeof(sockaddr)) == SOCKET_ERROR){<br />
        cout << "Error " << endl;<br />
    }<br />
    recv(dataSock, recvbuffer, 512, 0);<br />
    cout << recvbuffer << endl;<br />
   <br />
    while(1){<br />
        socketbuffer = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);<br />
        getsockname(socketbuffer, (LPSOCKADDR)&addr, NULL);<br />
        bind(socketbuffer, reinterpret_cast<SOCKADDR*>(&addr), sizeof(SOCKADDR_IN));<br />
        listen(socketbuffer, 10);<br />
        accept(socketbuffer, NULL,NULL);<br />
       <br />
        Sleep(1000);<br />
        ftpmsg("USER user\r\n");<br />
        Sleep(1000);<br />
        ftpmsg("PASS password\r\n");<br />
        Sleep(1000);<br />
        ftpmsg("PORT\r\n");<br />
        Sleep(1000);<br />
        ftpmsg("STOR file.txt\r\n");<br />
        Sleep(9000);<br />
        ftpmsg("QUIT\r\n");<br />
    }<br />
    WSACleanup();<br />
    return 0;<br />
}<br />
<br />
<br />
bool ftpmsg(const char *message)<br />
{   <br />
    if(send(dataSock, message, strlen(message), 0) == SOCKET_ERROR){<br />
        exit(1);<br />
        return false;<br />
    }<br />
    else{<br />
        return true;<br />
    }<br />
}<br />


Notice how i try to open a new socket in the while loop because you have to open a new socket so that the data can be transfered there. I understand that much. However im getting my binding or listen wrong. I've been told that i should thread the connection but i dont see why considering its meant to do one thing. If anyone has any suggestion please let me know. I've been up and down the FTP RFC and i pretty much understand how it works. Now i just need to get the coding part right. Thanx in advance!
AnswerRe: Simple FTP Client Pin
JudyL_MD1-Nov-07 10:20
JudyL_MD1-Nov-07 10:20 
AnswerRe: Simple FTP Client Pin
Peter Weyzen1-Nov-07 16:24
Peter Weyzen1-Nov-07 16:24 
GeneralRe: Simple FTP Client Pin
dellthinker1-Nov-07 17:07
dellthinker1-Nov-07 17:07 
GeneralRe: Simple FTP Client Pin
Peter Weyzen1-Nov-07 20:30
Peter Weyzen1-Nov-07 20:30 
GeneralRe: Simple FTP Client Pin
dellthinker2-Nov-07 6:53
dellthinker2-Nov-07 6:53 
GeneralRe: Simple FTP Client Pin
Peter Weyzen2-Nov-07 7:32
Peter Weyzen2-Nov-07 7:32 
GeneralRe: Simple FTP Client Pin
Bram van Kampen2-Nov-07 3:22
Bram van Kampen2-Nov-07 3:22 
QuestionWizard 2000 Style Wizard Pin
Larry Mills Sr1-Nov-07 7:14
Larry Mills Sr1-Nov-07 7:14 
QuestionCan I pass through a variable number of arguments to another function? Pin
jp-mocs1-Nov-07 6:25
jp-mocs1-Nov-07 6:25 
AnswerRe: Can I pass through a variable number of arguments to another function? Pin
Luc Pattyn1-Nov-07 7:12
sitebuilderLuc Pattyn1-Nov-07 7:12 
AnswerRe: Can I pass through a variable number of arguments to another function? Pin
Chris Losinger1-Nov-07 7:50
professionalChris Losinger1-Nov-07 7:50 
GeneralRe: Can I pass through a variable number of arguments to another function? Pin
jp-mocs1-Nov-07 12:17
jp-mocs1-Nov-07 12:17 
GeneralRe: Can I pass through a variable number of arguments to another function? Pin
jp-mocs2-Nov-07 5:44
jp-mocs2-Nov-07 5:44 
QuestionOn selection a word in CEdit, which messages windows return? Pin
Gofur Halmurat1-Nov-07 6:19
Gofur Halmurat1-Nov-07 6:19 
AnswerRe: On selection a word in CEdit, which messages windows return? Pin
Maximilien1-Nov-07 6:23
Maximilien1-Nov-07 6:23 
GeneralRe: On selection a word in CEdit, which messages windows return? Pin
Gofur Halmurat1-Nov-07 6:34
Gofur Halmurat1-Nov-07 6:34 
AnswerRe: On selection a word in CEdit, which messages windows return? Pin
Mark Salsbery1-Nov-07 7:01
Mark Salsbery1-Nov-07 7:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.