Click here to Skip to main content
15,917,971 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using FileZilla as my ftpserver....
My problem is that I want to rename a file programatically..

C#
public int RedenumireArticolServer(string adresaserver,string numearticolvechi, string numearticolnou)
        {
            try
            {
                //"c:/ArticoleAplicatieLicenta/"+
                string uri = "ftp://"+ adresaserver+ "/" +numearticolvechi+".dat";
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(uri);
                request.Credentials = new NetworkCredential("lucian", "lucian");
                request.RenameTo = numearticolnou+".dat";
                FtpWebResponse r = (FtpWebResponse)request.GetResponse();
            }
            catch (WebException e)
            {
                String status = ((FtpWebResponse)e.Response).StatusDescription;
                Console.WriteLine(status);
                return -1;
            }
            return 1;
        }



In Filezilla I have a user "lucian", and I have made a Sharedfolder in c:/ArticoleAplicatieLicenta , and set it as Homefolder


The code above, doesn't give any error, but It doesn't rename my file...

Can you help please?
Thank you .. :)
Posted

1 solution

this works (I founded somewhere on the internet and adapted to my case):

C#
public int RedenumireArticolServer(string adresaserver,string numearticolvechi, string numearticolnou)
        {
            FtpWebRequest reqFTP;
            try
            {
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + adresaserver + "/" + numearticolvechi+".dat"));
                reqFTP.Method = WebRequestMethods.Ftp.Rename;
                reqFTP.RenameTo = numearticolnou+".dat";
                reqFTP.UseBinary = true;
                reqFTP.Credentials = new NetworkCredential("lucian", "lucian");
                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                Stream ftpStream = response.GetResponseStream();

                ftpStream.Close();
                response.Close();
            }
           catch (WebException e)
            {
                String status = ((FtpWebResponse)e.Response).StatusDescription;
                Console.WriteLine(status);
               return -1;
           }
            return 1;
        }
 
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