FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old April 30th, 2004, 03:13 AM
kucing kucing is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 19 kucing User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old April 30th, 2004, 07:16 AM
mitakeet's Avatar
mitakeet mitakeet is offline
Last Day: May 28, 2005
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jul 2003
Location: Maryland
Posts: 4,575 mitakeet User rank is Sergeant (500 - 2000 Reputation Level)mitakeet User rank is Sergeant (500 - 2000 Reputation Level)mitakeet User rank is Sergeant (500 - 2000 Reputation Level)mitakeet User rank is Sergeant (500 - 2000 Reputation Level)mitakeet User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 8 h 5 m 34 sec
Reputation Power: 20
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

Reply With Quote
  #3  
Old April 30th, 2004, 10:59 AM
infamous41md's Avatar
infamous41md infamous41md is offline
not a fan of fascism (n00b)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Feb 2003
Location: ct
Posts: 2,756 infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 26
is that just an example, or the real code? why aren't u recieving in a loop?

Reply With Quote
  #4  
Old April 30th, 2004, 07:52 PM
kucing kucing is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 19 kucing User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > Receiving binary files in socket progamming (ftp)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway