while(1){
printf("FTP MODE\n");
if (send(sock, echoString, echoStringLen, 0) != echoStringLen)
DieWithError("send() sent a different number of bytes than expected");
if (recv(sock, echoBuffer, RCVBUFSIZE - 1, 0) <= 0)
DieWithError("recv() failed or connection closed prematurely");
echoBuffer[bytesRcvd] = '\0'; /* Terminate the string! */
printf(echoBuffer); /* Print the echo buffer */
printf("\n");
printf("name.ttt->:");
scanf("%s",echoString);
if(!strcmp(echoString,"/quit")){
printf("terminate\n");
close(sock);
exit(1);
}
echoStringLen = strlen(echoString); /* Determine input length */
FTP = fopen(echoString,"rb");
//file name send
if (send(sock, echoString, echoStringLen, 0) != echoStringLen)
DieWithError("send() sent a different number of bytes than expected");
//size req recv
if (recv(sock, echoBuffer, RCVBUFSIZE - 1, 0) <= 0)
DieWithError("recv() failed or connection closed prematurely");
fseek(FTP, 0, SEEK_END);
filesize = ftell(FTP);
fseek(FTP, 0, SEEK_SET);
sprintf(echoString,"%d",filesize);
//size send
if (send(sock, echoString, echoStringLen, 0) != echoStringLen)
DieWithError("send( size ) error ");
//file transport
printf("sending =>");
while(!feof(FTP)){
if(recv(sock,echoBuffer,RCVBUFSIZE - 1,0) <=0)
DieWithError("recv() failed");
FTPBUF[i++] = fgetc(FTP);
if(ftell(FTP) >= filesize/100*percent){
printf("#");
percent +=10;
}
if(i==256){
if(send(sock, FTPBUF,256,0) != 256)
DieWithError("send ( size ) errof ");
i=0;
}
}
for(j=0;j<i;j++){
FTPBUF[j] = fgetc(FTP);
}
...
while(1){
//file name.ttt req
msgBox = "filename to put to server->";
if(send(clntSocket, msgBox,strlen(msgBox),0) != strlen(msgBox))
DieWithError("send() failed");
printf("send request filename\n");
//file name recv
if((recvMsgSize = recv(clntSocket,FTPBuffer,FTPBUFSIZE, 0))<0)
DieWithError("recv() failed");
FTPBuffer[recvMsgSize] ='\0';
//file make
strcat(filename,FTPBuffer);
FTP = fopen (filename,"ab");
printf("fmake success\n");
//size req send
if(send(clntSocket, "size",5,0) != 5)
DieWithError("send() failed");
printf("send request size\n");
//size recv
if(recv(clntSocket,FTPBuffer,FTPBUFSIZE, 0)<0)
DieWithError("recv() failed");
FTPBuffer[recvMsgSize] ='\0';
filesize = atoi(FTPBuffer);
printf("size = %d\n",filesize);
//file transport
printf("sending =>");
while(1){
retval = recvn(clntSocket,FTPBuffer,256,0);
if(retval <0)
DieWithError("recv() failed");
else if(retval==0)
break;
else
fwrite(FTPBuffer,1,retval,FTP);
numtotal += retval;
}
...
파일이름을 주고받고
사이즈를 주고받고
sending msg => 를 출력하고
이제 반복문에 들어가야 하는데여
sending msg => 를 출력 못하고 그냥 거기서 정체가 되요
이해가 안되는것은 파일이름과 사이즈를 제대로 잘 주고받고
그에 맞게 파일도 열고 사이즈도 잘 출력하는데
왜 그 바로 다음에 표준출력인 sending msg 부터 막히는걸까요
파일네임 길이도 먼저 고정길이로 보내셔야함
FTPBUFSIZE 만큼 받으시면안대여
되요->돼요 (되어 = 돼임) [리듬 맞춤법 봇♬]