Exemplo n.º 1
0
        /// <summary>
        /// Upload a file to a FTP server and creates all the sub directories relative to root
        /// </summary>
        public void UploadFile(string file, string host, string ftpUsername, string ftpPassword)
        {
            if (!system.FileExists(file))
            {
                throw new ArgumentException(string.Format("file {0} does not exists", file));
            }
            // Get the relative dirs path from local drive
            string directorypaths = system.GetDirPathFromRoot(file);

            if (!String.IsNullOrEmpty(directorypaths))
            {
                CreateDirectory(directorypaths, host, ftpUsername, ftpPassword);
            }
            // Upload the file to the ftp server
            string relativepath = system.GetPathFromRoot(file);

            new WebClient().FtpUploadRequest(BuildFTPRequestURI(host, relativepath)
                                             , file
                                             , host
                                             , ftpUsername
                                             , ftpPassword);
        }