Beispiel #1
0
        static public bool Exist(nilnul.web.UrlI4 url, NetworkCredential cred)
        {
            //string url = "ftp://ftp.example.com/remote/path/file.txt";

            var request = (FtpWebRequest)WebRequest.Create(url.ToString());

            request.Credentials = cred;                                   // new NetworkCredential("username", "password");
            request.Method      = WebRequestMethods.Ftp.GetDateTimestamp; // WebRequestMethods.Ftp.GetFileSize;

            /*Because
             * request.Method = WebRequestMethods.Ftp.GetFileSize
             * may fails in some case (550: SIZE not allowed in ASCII mode), you can just check Timestamp instead.*/

            request.UseBinary = true;
            try
            {
                request.GetResponse();
                return(true);
            }
            catch (WebException e)
            {
                FtpWebResponse response = (FtpWebResponse)e.Response;
                if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
                {
                    Trace.WriteLine("Does not exist");
                    return(false);
                }
                else
                {
                    Trace.WriteLine("Error: " + e.Message);
                    throw;
                }
            }
        }
Beispiel #2
0
        static public void Download(NetworkCredential cred, nilnul.web.UrlI4 url, nilnul.fs.address_.SpearI spear)
        {
            WebClient client = new WebClient();

            client.Credentials = cred;          // new NetworkCredential("username", "password");
            client.DownloadFile(
                url.ToString()                  //"ftp://ftp.example.com/remote/path/file.zip"
                ,
                spear.ToString()                //@"C:\local\path\file.zip"
                );
        }