|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Receiving binary files in socket progamming (ftp)
Hi, I am currently writing an FTP program. The program that I have written can get ASCII files but not binary files. I am not sure onwhat to do for binary files
. Here is part of the code that tries to get the binary file.Code:
string msg; char acceptBuffer[10000]; ... msg = "retr picture.jpg\n"; // Binary file send(sockfd, msg.c_str(), msg.size(), 0); int sockfd2 = socket(AF_INET, SOCK_STREAM, 0); target_address.sin_port = htons(dataSocket); connect(sockfd2, (struct sockaddr *)&target_address, sizeof(struct sockaddr)); int lengthRecv = recv(sockfd2, acceptBuffer, MAXDATASIZE, 0); ofstream outFile(saveAs.c_str(), ios::out|ios::binary); outFile.write(acceptBuffer, lengthRecv); Recv always receives an amount smaller than the real size of the file everytime I try to download a binary file. But for ASCII file it outputs properly. I have changed the type of transfer mode to binary by sending "type i" earlier in the program. Does it mean that I can not use recv? What should I use instead to download binary files then? Any help is appreciated. |
|
#2
|
||||
|
||||
|
Have you instructed the FTP Server to send the file in binary mode? Many servers have a default value of ASCII.
__________________
Left DevShed May 28, 2005. Reason: Unresponsive administrators. Free code: http://sol-biotech.com/code/. Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html. Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html. It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it. --Me, I just made it up The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man. --George Bernard Shaw |
|
#3
|
||||
|
||||
|
is that just an example, or the real code? why aren't u recieving in a loop?
__________________
|
|
#4
|
|||
|
|||
|
Thanks guy, I finally figure out what's wrong. Apparently it is caused by lag. And I set the lag tolerance in recv to 0. Changing it to:
Code:
int lengthRecv = recv(sockfd2, acceptBuffer, MAXDATASIZE, 1000); makes the code work properly .Last edited by kucing : April 30th, 2004 at 08:36 PM. |
![]() |
| Viewing: Dev Shed Forums > System Administration > FTP Help > Receiving binary files in socket progamming (ftp) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|