Esempio n. 1
0
        /// <summary>
        /// 获取目录下的directory 和files
        /// </summary>
        /// <returns></returns>
        public String[] getAllFiles()
        {
            StringBuilder result = new StringBuilder();

            try
            {
                foreach (var dir in conn.GetDirectories(conn.GetCurrentDirectory()))
                {
                    result
                    .Append(dir.Attributes.ToString()).Append("?")
                    .Append(dir.Name).Append("?")
                    .Append("0").Append("?")
                    .Append(dir.LastWriteTime).Append("?")
                    .Append("\n");
                }
                foreach (var f in conn.GetFiles(conn.GetCurrentDirectory()))
                {
                    result
                    .Append(f.Attributes).Append("?")
                    .Append(f.Name).Append("?")
                    .Append(conn.GetFileSize(conn.GetCurrentDirectory() + "/" + f.Name)).Append("?")
                    .Append(f.LastWriteTime).Append("?")
                    .Append("\n");
                }
            }
            catch
            {
                MessageBox.Show("ftp has lost connection!", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(result.ToString().Split('\n'));
        }
Esempio n. 2
0
        private void DownloadFile(FtpConnection ftp, FtpFileInfo ftpFileInfo, string remotePath, string localPath)
        {
            ConsoleService.WriteToConsole("Downloading " + ftpFileInfo.Name + " (" + FormatHelper.ConvertToHumanReadbleFileSize(ftp.GetFileSize(remotePath + "/" + ftpFileInfo.Name)) + ")");
            if (!Directory.Exists(localPath))
            {
                Directory.CreateDirectory(localPath);
            }

            var filePath = Path.Combine(localPath, ftpFileInfo.Name);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            ftp.GetFile(remotePath + "/" + ftpFileInfo.Name, filePath, false);
        }