Click here to Skip to main content
15,887,272 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void LinkButton1_Click(object sender, EventArgs e)
 {
    string filename = @"C:\inetpub\ftproot\RetailAgreement\abc.JPG"; 
    string ftpServerIP = "192.148.10.10";
    string ftpUserID = "username";
    string ftpPassword = "password";

    System.IO.FileInfo fileInf = new FileInfo(filename);

    string uri = "ftp://" + ftpServerIP + "/RetailAgreement/" + fileInf.Name;
    FtpWebRequest reqFTP;      
    reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/RetailAgreement/" + fileInf.Name));
    reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
    reqFTP.KeepAlive = false;
    reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
    reqFTP.UseBinary = true;
    int buffLength = 2048;
    byte[] buff = new byte[buffLength];
    int contentLen;
    FileStream fs = fileInf.OpenRead();                   

    Stream strm = reqFTP.GetRequestStream();

        // 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);
        }
        // Close the file stream and the Request Stream
        strm.Close();
        fs.Close();             
}



i gave file name in my server system existing correct path,but i am getting an exception like could not find file path exception....please correct me?
Posted
Updated 2-Mar-14 18:11pm
v2
Comments
george4986 3-Mar-14 0:30am    
is the username and password is correct?
Siva Hyderabad 3-Mar-14 0:46am    
yes,but it shows like this..
Siva Hyderabad 3-Mar-14 0:46am    
how to check my username ,password correct or not?
george4986 3-Mar-14 0:50am    
where did u hosted the application on ur server or any provider?
Siva Hyderabad 3-Mar-14 0:52am    
server

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900