Click here to Skip to main content
15,890,825 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: button disable until all required fields are filled Pin
Member 870181321-Feb-13 5:00
Member 870181321-Feb-13 5:00 
GeneralRe: button disable until all required fields are filled Pin
Member 870181320-Feb-13 22:09
Member 870181320-Feb-13 22:09 
QuestionPlease Wait .... Pin
jojoba201119-Feb-13 21:19
jojoba201119-Feb-13 21:19 
AnswerRe: Please Wait .... Pin
Sandeep Mewara19-Feb-13 22:11
mveSandeep Mewara19-Feb-13 22:11 
AnswerRe: Please Wait .... Pin
Karthik Harve20-Feb-13 19:07
professionalKarthik Harve20-Feb-13 19:07 
QuestionRe: Please Wait .... Pin
jojoba201122-Feb-13 23:26
jojoba201122-Feb-13 23:26 
Questionftp uploaded files are empty Pin
Omid Reza Aryafar19-Feb-13 2:43
Omid Reza Aryafar19-Feb-13 2:43 
AnswerRe: ftp uploaded files are empty Pin
Richard Deeming19-Feb-13 4:17
mveRichard Deeming19-Feb-13 4:17 
Omid Reza Aryafar wrote:
FileStream localFileStream = new FileStream(localFile, FileMode.Create);

There's your problem:
Create: Specifies that the operating system should create a new file. If the file already exists, it will be overwritten.

You should be passing FileMode.Open to the FileStream constructor. Alternatively, use the File.OpenRead method[^] to open the file.

You should also wrap the localFileStream and ftpRequest in using blocks to make sure they're closed if anything goes wrong.

C#
public void uploadFile(string remoteFile, string localFile)
{
   try
   {
      using (var ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + remoteFile))
      {
         ftpRequest.Credentials = new NetworkCredential(user, pass);
         ftpRequest.UseBinary = true;
         ftpRequest.UsePassive = true;
         ftpRequest.KeepAlive = true;
         ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;

         using (var ftpStream = ftpRequest.GetRequestStream())
         using (var localFileStream = File.OpenRead(localFile))
         {
            byte[] byteBuffer = new byte[bufferSize];
            int bytesRead = localFileStream.Read(byteBuffer, 0, bufferSize);
            while (bytesRead != 0)
            {
               ftpStream.Write(byteBuffer, 0, bytesRead);
               bytesRead = localFileStream.Read(byteBuffer, 0, bufferSize);
            }
         }
      }
   }
   catch (Exception ex)
   {
      Console.WriteLine(ex);
   }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: ftp uploaded files are empty Pin
Omid Reza Aryafar19-Feb-13 4:34
Omid Reza Aryafar19-Feb-13 4:34 
QuestionCan a Compare validator fire when either of two controls changes? Pin
darookie9918-Feb-13 17:13
darookie9918-Feb-13 17:13 
AnswerRe: Can a Compare validator fire when either of two controls changes? Pin
Brij18-Feb-13 19:09
mentorBrij18-Feb-13 19:09 
GeneralRe: Can a Compare validator fire when either of two controls changes? Pin
darookie9919-Feb-13 13:51
darookie9919-Feb-13 13:51 
AnswerRe: Can a Compare validator fire when either of two controls changes? Pin
ZurdoDev19-Feb-13 2:32
professionalZurdoDev19-Feb-13 2:32 
AnswerRe: Can a Compare validator fire when either of two controls changes? Pin
Keith Barrow19-Feb-13 4:07
professionalKeith Barrow19-Feb-13 4:07 
Questionmultilanguage application Pin
Member 870181318-Feb-13 7:39
Member 870181318-Feb-13 7:39 
AnswerRe: multilanguage application Pin
Sandeep Mewara18-Feb-13 7:58
mveSandeep Mewara18-Feb-13 7:58 
GeneralRe: multilanguage application Pin
Member 870181325-Feb-13 21:59
Member 870181325-Feb-13 21:59 
GeneralRe: multilanguage application Pin
Sandeep Mewara25-Feb-13 23:24
mveSandeep Mewara25-Feb-13 23:24 
GeneralRe: multilanguage application Pin
Member 870181326-Feb-13 1:44
Member 870181326-Feb-13 1:44 
GeneralRe: multilanguage application Pin
Sandeep Mewara26-Feb-13 2:04
mveSandeep Mewara26-Feb-13 2:04 
GeneralRe: multilanguage application Pin
Member 870181326-Feb-13 2:51
Member 870181326-Feb-13 2:51 
GeneralRe: multilanguage application Pin
Member 870181326-Feb-13 5:20
Member 870181326-Feb-13 5:20 
AnswerRe: multilanguage application Pin
Sandeep Mewara26-Feb-13 5:38
mveSandeep Mewara26-Feb-13 5:38 
GeneralRe: multilanguage application Pin
Member 870181327-Feb-13 4:38
Member 870181327-Feb-13 4:38 
GeneralRe: multilanguage application Pin
Sandeep Mewara27-Feb-13 4:48
mveSandeep Mewara27-Feb-13 4:48 

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.