Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey there,
I want to create a login for my program.
On my attic I have a server (FTP possible). To get data from the server I have to enter an username and a password. How can I access the server into my program and how can I create folders, copy databases and rename them?
Please help me.
Posted
Comments
PIEBALDconsult 22-Nov-15 12:15pm    
Does the FTP server/client software have an API? If not, you may need to automate the command-line interface.

C#
static void Main()
   {
       WebRequest request = WebRequest.Create("ftp://host.com/directory");
       request.Method = WebRequestMethods.Ftp.MakeDirectory;
       request.Credentials = new NetworkCredential("user", "pass");
       using (var resp = (FtpWebResponse) request.GetResponse())
       {
           Console.WriteLine(resp.StatusCode);
       }
   }



Please take a look the following posts

Make Directory on FTP using C#[^]

http://stackoverflow.com/questions/860638/how-do-i-create-a-directory-on-ftp-server-using-c[^]
 
Share this answer
 
Try this..

C#
string CompleteDPath = "ftp://192.168.1.1:3113/YourFolderName/" + filephoto;
                string UName = "FTP UserName";
                string PWD = "FTP Password";
                //Filepath = CompleteDPath + MATBR + "/M_" + DIST + "_" + schlcode + "_lot_" + printlot.ToString() + ".pdf";
                fu_photo.SaveAs(Server.MapPath("images//") + filephoto);

                WebRequest reqObj = WebRequest.Create(CompleteDPath);
                reqObj.Method = WebRequestMethods.Ftp.UploadFile;
                reqObj.Credentials = new NetworkCredential(UName, PWD);
                FileStream streamObj = System.IO.File.OpenRead(Server.MapPath("Images//" + filephoto));
                byte[] buffer = new byte[streamObj.Length + 1];
                streamObj.Read(buffer, 0, buffer.Length);
                streamObj.Close();
                streamObj = null;
                reqObj.GetRequestStream().Write(buffer, 0, buffer.Length);
                reqObj = null;


Regards,
AARIF SHAIKH
 
Share this answer
 

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