Click here to Skip to main content


AnswerRe: Please Wait .... PinmvpSandeep Mewara19-Feb-13 23:11 
AnswerRe: Please Wait .... PinmemberKarthik Harve20-Feb-13 20:07 
QuestionRe: Please Wait .... Pinmemberjojoba201123-Feb-13 0:26 
Questionftp uploaded files are empty [modified] PinmemberOmid Reza Aryafar19-Feb-13 3:43 
Hi every one,
strange issue, im trying to upload a whole simple one-page website to a remote ftp by my method called uploadFolderContents().
every structure and files gets uploade, but the contents of files are gone. all of them are empty even txt files.
i tried to upload a single txt file, the file appears on remote but empty as well.
oh, it also changes the source files, makes them all empty too!!!!
some hlp pls

            clsFile.ftp ftp = new clsFile.ftp("ftp", "un", "pwd");
            ftp.uploadFolderContents("httpdocs/omid", "E:\\omid");

public bool uploadFolderContents(string remoteFolder, string localFolder)
            bool rslt = false;
                string[] files = Directory.GetFiles(localFolder);
                string[] dirs = Directory.GetDirectories(localFolder);
                foreach (string file in files)
                    uploadFile(remoteFolder + "/" + Path.GetFileName(file), file);
                foreach (string dir in dirs)
                    createFolder(remoteFolder + "/" + Path.GetFileName(dir));
                    uploadFolderContents(remoteFolder + "/" + Path.GetFileName(dir), dir);
                rslt = true;
            catch (Exception)
                rslt = false;
            return rslt;

public void uploadFile(string remoteFile, string localFile)
        /* Create an FTP Request */
        ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + remoteFile);
        /* Log in to the FTP Server with the User Name and Password Provided */
        ftpRequest.Credentials = new NetworkCredential(user, pass);
        /* When in doubt, use these options */
        ftpRequest.UseBinary = true;
        ftpRequest.UsePassive = true;
        ftpRequest.KeepAlive = true;
        /* Specify the Type of FTP Request */
        ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
        /* Establish Return Communication with the FTP Server */
        ftpStream = ftpRequest.GetRequestStream();
        /* Open a File Stream to Read the File for Upload */
        FileStream localFileStream = new FileStream(localFile, FileMode.Create);
        /* Buffer for the Downloaded Data */
        byte[] byteBuffer = new byte[bufferSize];
        int bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
        /* Upload the File by Sending the Buffered Data Until the Transfer is Complete */
            while (bytesSent != 0)
                ftpStream.Write(byteBuffer, 0, bytesSent);
                bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
        catch (Exception ex) { Console.WriteLine(ex.ToString()); }
        /* Resource Cleanup */
        ftpRequest = null;
    catch (Exception ex) { Console.WriteLine(ex.ToString()); }

modified 19-Feb-13 8:55am.

AnswerRe: ftp uploaded files are empty PinmemberRichard Deeming19-Feb-13 5:17 
GeneralRe: ftp uploaded files are empty PinmemberOmid Reza Aryafar19-Feb-13 5:34 
QuestionCan a Compare validator fire when either of two controls changes? Pinmemberdarookie9918-Feb-13 18:13 
AnswerRe: Can a Compare validator fire when either of two controls changes? PinmentorBrij18-Feb-13 20:09 
GeneralRe: Can a Compare validator fire when either of two controls changes? Pinmemberdarookie9919-Feb-13 14:51 
AnswerRe: Can a Compare validator fire when either of two controls changes? Pinmemberryanb3119-Feb-13 3:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Advertise | Privacy | Mobile
Web01 | 2.8.150327.1 | Last Updated 27 Mar 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid