Click here to Skip to main content
15,887,350 members
Home / Discussions / C#
   

C#

 
GeneralRe: Error 404 Pin
vunhat4-Jun-07 10:19
vunhat4-Jun-07 10:19 
GeneralRe: Error 404 Pin
Dan Neely4-Jun-07 11:25
Dan Neely4-Jun-07 11:25 
GeneralRe: Error 404 Pin
vunhat4-Jun-07 11:29
vunhat4-Jun-07 11:29 
GeneralRe: Error 404 Pin
Jasmine25014-Jun-07 11:35
Jasmine25014-Jun-07 11:35 
QuestionHTML Parsing question Pin
bs99994-Jun-07 7:02
bs99994-Jun-07 7:02 
AnswerRe: HTML Parsing question Pin
Jasmine25014-Jun-07 7:44
Jasmine25014-Jun-07 7:44 
QuestionMaking DTS Package in C#? Pin
Gul_#4-Jun-07 6:09
Gul_#4-Jun-07 6:09 
QuestionFTP Upload, problem to close stream Pin
wojti4-Jun-07 6:05
wojti4-Jun-07 6:05 
Hi,


I have a method to upload file using FTP.

By uploading to the one of the FTP server I have a problem by closing stream.

The file is uploaded successfully but when I try to close stream, then my application hangs up.


This is in line: strm.Close();



On some other FTP server everything works fine. Could be it a problem with FTP server? I gewt this error only by working with larger files.


How schould I solve it? Is it allways neccessary to close the stream?


Thanks


Wojtek



Bellow my upload method



Stream strm = null;

FileStream fs = null;

try

{

DirectoryInfo dirInfo = new DirectoryInfo(source);

//upload all archive file from source directory

foreach (FileInfo fileInfo in dirInfo.GetFiles("*.rar"))

{

// get the object used to communicate with the server

FtpWebRequest request = (FtpWebRequest)WebRequest.Create(new Uri(string.Concat(hostName, "/", fileInfo.Name)));

//set ftp method

request.Method = WebRequestMethods.Ftp.UploadFile;

request.UseBinary = true;

request.Timeout = timeout * 1000;

request.UsePassive = true;

// set credentials

request.Credentials = new NetworkCredential(userName, password);

// the buffer size is set to 2kb

int buffLength = 2048;

byte[] buff = new byte[buffLength];

int contentLen;

// opens a file stream (System.IO.FileStream) to read the file to be uploaded

fs = fileInfo.OpenRead();

// stream to which the file to be upload is written

strm = request.GetRequestStream();

strm.ReadTimeout = 5000;

// read from the file stream 2kb at a time

contentLen = fs.Read(buff, 0, buffLength);

// till Stream content ends

while (contentLen != 0)

{

// write Content from the file stream to the FTP Upload Stream

strm.Write(buff, 0, contentLen);

contentLen = fs.Read(buff, 0, buffLength);

}

}

}

catch (WebException e)

{

output.AppendLine(e.Message);

}

catch (InvalidOperationException e)

{

output.AppendLine(e.Message);

}

catch (Exception e)

{

output.AppendLine(e.Message);

}

finally

{

// close the file stream

fs.Close();

strm.Close();


QuestionDeleting log file using WMI ? Pin
Software_Specialist4-Jun-07 5:36
Software_Specialist4-Jun-07 5:36 
QuestionnUnit & C# express Pin
Justin Perez4-Jun-07 4:25
Justin Perez4-Jun-07 4:25 
AnswerRe: nUnit & C# express Pin
Bekjong4-Jun-07 4:32
Bekjong4-Jun-07 4:32 
AnswerRe: nUnit & C# express Pin
Paul Conrad4-Jun-07 6:05
professionalPaul Conrad4-Jun-07 6:05 
Questionxml serialization problem in c# Pin
ksrs4-Jun-07 4:15
ksrs4-Jun-07 4:15 
AnswerRe: xml serialization problem in c# Pin
Sathesh Sakthivel4-Jun-07 4:22
Sathesh Sakthivel4-Jun-07 4:22 
GeneralRe: xml serialization problem in c# Pin
ksrs4-Jun-07 5:03
ksrs4-Jun-07 5:03 
GeneralRe: xml serialization problem in c# Pin
Sathesh Sakthivel4-Jun-07 5:54
Sathesh Sakthivel4-Jun-07 5:54 
QuestionRe: xml serialization problem in c# Pin
ksrs5-Jun-07 5:08
ksrs5-Jun-07 5:08 
AnswerRe: xml serialization problem in c# Pin
Sathesh Sakthivel5-Jun-07 15:21
Sathesh Sakthivel5-Jun-07 15:21 
AnswerRe: xml serialization problem in c# Pin
Jaiprakash M Bankolli4-Jun-07 7:16
Jaiprakash M Bankolli4-Jun-07 7:16 
QuestionRe: xml serialization problem in c# Pin
ksrs5-Jun-07 5:17
ksrs5-Jun-07 5:17 
Questionmultiple form indows application in C# Pin
sanki7794-Jun-07 3:09
sanki7794-Jun-07 3:09 
AnswerRe: multiple form Windows application in C# Pin
sanki7794-Jun-07 3:09
sanki7794-Jun-07 3:09 
AnswerRe: multiple form indows application in C# Pin
Colin Angus Mackay4-Jun-07 3:18
Colin Angus Mackay4-Jun-07 3:18 
GeneralRe: multiple form indows application in C# Pin
sanki7794-Jun-07 3:40
sanki7794-Jun-07 3:40 
QuestionWorking with the MS Office Interop Assemblies --- Need help Pin
Xprt4-Jun-07 2:03
Xprt4-Jun-07 2:03 

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.