Click here to Skip to main content
15,898,010 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to determine if two C# exe come from the same source Pin
Scott Dorman14-Jan-09 10:02
professionalScott Dorman14-Jan-09 10:02 
AnswerRe: How to determine if two C# exe come from the same source Pin
User 665814-Jan-09 10:04
User 665814-Jan-09 10:04 
AnswerRe: How to determine if two C# exe come from the same source [modified] Pin
Luc Pattyn14-Jan-09 10:12
sitebuilderLuc Pattyn14-Jan-09 10:12 
GeneralRe: How to determine if two C# exe come from the same source Pin
PIEBALDconsult14-Jan-09 16:57
mvePIEBALDconsult14-Jan-09 16:57 
AnswerRe: How to determine if two C# exe come from the same source Pin
Daniel Grunwald14-Jan-09 12:48
Daniel Grunwald14-Jan-09 12:48 
AnswerRe: How to determine if two C# exe come from the same source Pin
Henry Minute14-Jan-09 13:31
Henry Minute14-Jan-09 13:31 
Questionmultiple icons in exe with alpha Pin
Xmen Real 14-Jan-09 5:59
professional Xmen Real 14-Jan-09 5:59 
QuestionProblem transferring file with FTP using Socket Pin
Member 321680814-Jan-09 5:50
Member 321680814-Jan-09 5:50 
Hi there Smile | :)

I have written an application that attempts to transfer a file using the Socket class. I am able to set up the command socket and the data socket just fine, and transfer *most* of the file. The problem is that the file size on the server after being transferred is smaller than the number of bytes my software says it transferred. If I use a third-party FTP product, such as Core FTP, to download the file I just uploaded, the file is still too short by less than the length of my transfer buffer.

My upload code is:
// Get a separate socket for the data transfer
Socket dataSocket = GetDataSocket(cmdSocket);
// Start uploading!
int numBytesRead = 0;
byte[] byteBuffer = new byte[TRANSFER_BUFFER_SIZE];
int m_BytesTransferred = 0;
while ((numBytesRead = fs.Read(byteBuffer, 0, TRANSFER_BUFFER_SIZE)) > 0 && !m_Cancel)
{
try
{
dataSocket.Send(byteBuffer, numBytesRead, SocketFlags.None);
m_BytesTransferred += (long)numBytesRead;
// This is to let my UI update the progress meter
Thread.Sleep(20);
}
catch (SocketException ex)
{
break;
}
}
// Finished with the file, so close it.
fs.Close();
if (dataSocket.Connected)
{
Thread.Sleep(500);
dataSocket.Shutdown(SocketShutdown.Both);
dataSocket.Close();
}

My download code is:
Socket dataSocket = GetDataSocket(cmdSocket);
string retString = "";
m_BytesTransferred = 0;
// Set the time when we will give up on the transfer
DateTime endTime = DateTime.Now.AddSeconds(5.0);
int numBytesRecd = 0;
byte[] transferBuffer = new byte[TRANSFER_BUFFER_SIZE];
while (endTime > DateTime.Now && !m_Cancel)
{
numBytesRecd = dataSocket.Receive(transferBuffer, TRANSFER_BUFFER_SIZE, SocketFlags.None);
if (numBytesRecd <= 0)
{
break;
}
fs.Write(transferBuffer, 0, numBytesRecd);
m_BytesTransferred += (long)numBytesRecd;

// Reset the time when we will give up if we just received some bytes
endTime = DateTime.Now.AddSeconds(10.0);
Thread.Sleep(20);
}
// All done writing to the file
fs.Close();
if (dataSocket.Connected)
{
dataSocket.Close();
}

I have verified that the portion of the file that has been transferred is the same as the original file. I have even put in a Thread.Sleep(500) to wait for the last buffer to transfer before calling Socket.Shutdown() and Socket.Close(). Nothing has worked. Any suggestions?
AnswerRe: Problem transferring file with FTP using Socket Pin
Mark Salsbery14-Jan-09 13:35
Mark Salsbery14-Jan-09 13:35 
GeneralRe: Problem transferring file with FTP using Socket Pin
Member 321680815-Jan-09 2:41
Member 321680815-Jan-09 2:41 
AnswerRe: Problem transferring file with FTP using Socket Pin
Bharat Jain29-Jan-09 19:47
Bharat Jain29-Jan-09 19:47 
QuestionSend UDP string via proxy [modified] Pin
s.sala14-Jan-09 4:05
s.sala14-Jan-09 4:05 
AnswerRe: Send UDP string via proxy Pin
Bharat Jain14-Jan-09 4:27
Bharat Jain14-Jan-09 4:27 
GeneralRe: Send UDP string via proxy Pin
s.sala14-Jan-09 4:59
s.sala14-Jan-09 4:59 
GeneralRe: Send UDP string via proxy Pin
Bharat Jain29-Jan-09 19:27
Bharat Jain29-Jan-09 19:27 
QuestionGetting column value from binding Pin
kanchoette14-Jan-09 4:00
kanchoette14-Jan-09 4:00 
AnswerRe: Getting column value from binding Pin
moon_stick14-Jan-09 4:15
moon_stick14-Jan-09 4:15 
GeneralRe: Getting column value from binding Pin
kanchoette14-Jan-09 21:30
kanchoette14-Jan-09 21:30 
GeneralRe: Getting column value from binding Pin
moon_stick14-Jan-09 21:57
moon_stick14-Jan-09 21:57 
GeneralRe: Getting column value from binding Pin
kanchoette14-Jan-09 22:09
kanchoette14-Jan-09 22:09 
GeneralRe: Getting column value from binding Pin
moon_stick14-Jan-09 22:45
moon_stick14-Jan-09 22:45 
AnswerRe: Getting column value from binding Pin
moon_stick14-Jan-09 22:51
moon_stick14-Jan-09 22:51 
GeneralRe: Getting column value from binding Pin
kanchoette14-Jan-09 23:39
kanchoette14-Jan-09 23:39 
GeneralRe: Getting column value from binding Pin
moon_stick14-Jan-09 23:49
moon_stick14-Jan-09 23:49 
GeneralRe: Getting column value from binding Pin
kanchoette14-Jan-09 23:55
kanchoette14-Jan-09 23:55 

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.