本文介绍了使用Filezilla和C#重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用FileZilla作为我的ftpserver ....

我的问题是我想以编程方式重命名文件..



I am using FileZilla as my ftpserver....
My problem is that I want to rename a file programatically..

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;
        }







在Filezilla我有一个用户lucian,我做了c:/ ArticoleAplicatieLicenta中的Sharedfolder,并将其设置为Homefolder





上面的代码,没有任何错误,但是它没有重命名我的文件...



你能帮忙吗?

谢谢.. :))




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 .. :)

推荐答案

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;
        }


这篇关于使用Filezilla和C#重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 07:06