Exemple #1
0
        public static void FTPFailed(string param, string id)
        {
            string HOST_NAME        = "-";
            string USER_NAME        = "-";
            string PASSWORD         = "******";
            string HOST_NAME_FAILED = "-";

            CommonDBHelper Repo = CommonDBHelper.Instance;

            List <FTPCredential> data = Repo.GetFtpCredentialSucc(param, id, "GetFtpDownloadCredential").ToList();

            foreach (FTPCredential row in data)
            {
                HOST_NAME        = row.HOST_NAME;
                HOST_NAME_FAILED = row.HOST_NAME_FAILED;
                USER_NAME        = row.USER_NAME;
                PASSWORD         = row.PASSWORD;
            }

            NetworkCredential cred = new NetworkCredential(USER_NAME, PASSWORD);

            WebClient request = new WebClient();

            request.Credentials = new NetworkCredential(USER_NAME, PASSWORD);

            List <DirectoryItem> listing = GetDirectoryInformation(HOST_NAME, USER_NAME, PASSWORD);//"ftp://ftp.mywebsite.com/directory", "username", "password");

            string name = listing[0].Name;

            //CopyFile(HOST_NAME + name, HOST_NAME_FAILED + name, USER_NAME, PASSWORD);

            System.Net.FtpWebRequest clsRequest = (System.Net.FtpWebRequest)System.Net.WebRequest.Create(HOST_NAME + name);
            clsRequest.Credentials = new System.Net.NetworkCredential(USER_NAME, PASSWORD);
            clsRequest.Method      = System.Net.WebRequestMethods.Ftp.DeleteFile;

            System.Net.FtpWebResponse resp = (FtpWebResponse)clsRequest.GetResponse();
            resp.Close();

            //byte[] filedata = request.DownloadData(HOST_NAME + name); //Path.GetFileName(filename));

            //using (FileStream file = File.Create(filename + name))
            //{
            //    file.Write(filedata, 0, filedata.Length);
            //    file.Close();
            //}

            //return filename + name;
        }