Click here to Skip to main content
11,490,801 members (74,759 online)
   

ASP.NET

 
AnswerRe: Please Wait .... Pin
Sandeep Mewara19-Feb-13 23:11
mvpSandeep Mewara19-Feb-13 23:11 
AnswerRe: Please Wait .... Pin
Karthik Harve20-Feb-13 20:07
memberKarthik Harve20-Feb-13 20:07 
QuestionRe: Please Wait .... Pin
jojoba201123-Feb-13 0:26
memberjojoba201123-Feb-13 0:26 
Questionftp uploaded files are empty [modified] Pin
Omid Reza Aryafar19-Feb-13 3:43
memberOmid Reza Aryafar19-Feb-13 3:43 
Hi every one,

strange issue, im trying to upload a whole simple one-page asp.net 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;
 
            try
            {
                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)
{
    try
    {
        /* 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 */
        try
        {
            while (bytesSent != 0)
            {
                ftpStream.Write(byteBuffer, 0, bytesSent);
                bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
            }
        }
        catch (Exception ex) { Console.WriteLine(ex.ToString()); }
        /* Resource Cleanup */
        localFileStream.Close();
        ftpStream.Close();
        ftpRequest = null;
    }
    catch (Exception ex) { Console.WriteLine(ex.ToString()); }
    return;
}


modified 19-Feb-13 8:55am.

AnswerRe: ftp uploaded files are empty Pin
Richard Deeming19-Feb-13 5:17
memberRichard Deeming19-Feb-13 5:17 
GeneralRe: ftp uploaded files are empty Pin
Omid Reza Aryafar19-Feb-13 5:34
memberOmid Reza Aryafar19-Feb-13 5:34 
QuestionCan a Compare validator fire when either of two controls changes? Pin
darookie9918-Feb-13 18:13
memberdarookie9918-Feb-13 18:13 
AnswerRe: Can a Compare validator fire when either of two controls changes? Pin
Brij18-Feb-13 20:09
mentorBrij18-Feb-13 20:09 
GeneralRe: Can a Compare validator fire when either of two controls changes? Pin
darookie9919-Feb-13 14:51
memberdarookie9919-Feb-13 14:51 
AnswerRe: Can a Compare validator fire when either of two controls changes? Pin
ryanb3119-Feb-13 3:32
memberryanb3119-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.150520.1 | Last Updated 27 May 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid