【问题标题】:Copy folders through FTP in Windows在 Windows 中通过 FTP 复制文件夹
【发布时间】:2016-04-07 10:19:51
【问题描述】:

我有一个 Windows 2012 服务器,我试图通过 FTP 复制一个文件夹。该文件夹包含多个文件夹,大小约为 12 GB。 什么命令可以用来复制整个树结构,包括里面的所有文件夹和文件。

  • 我无法压缩此文件夹。
  • 我也尝试过使用mget*,但它会从所有 文件夹,但不创建文件夹结构。
  • 我无法使用 TAR 命令,因为提示显示“无效命令”。

【问题讨论】:

标签: windows ftp


【解决方案1】:

Windows 命令行 FTP 客户端 ftp.exe 不支持递归目录传输。


您必须为此使用第 3 方 FTP 客户端。

例如使用WinSCP FTP client,您可以使用如下批处理文件:

winscp.com /command ^
    "open ftp://user:password@example.com/" ^
    "get /folder/* c:\target\" ^
    "exit"

它会自动下载/folder中的所有文件和子文件夹。

有关详细信息,请参阅automating file transfers from FTP server 的 WinSCP 指南。还有一个转换Windows ftp.exe script to WinSCP的指南。

(我是 WinSCP 的作者)

【讨论】:

    【解决方案2】:

    目标目录是一个 zip 文件。您可以使用以下代码将完整的 zip 文件复制到 ftp 服务器中。

    //Taking source and target directory path
    string sourceDir = FilePath + "Files\\" + dsCustomer.Tables[0].Rows[i][2].ToString() + "\\ConfigurationFile\\" + dsSystems.Tables[0].Rows[j][0].ToString() + "\\XmlFile";
    
    string targetDir = FilePath + "Files\\Customers\\" + CustomerName + "\\" + SystemName + "\\";                                                                                       
    foreach (var srcPath in Directory.GetFiles(sourceDir))
    {
        //Taking file name which is going to copy from the sourcefile                                              
        string result = System.IO.Path.GetFileName(srcPath);
    
        //If that filename exists in the target path
        if (File.Exists(targetDir + result))
        {
            //Copy file with a different name(appending "Con_" infront of the original filename)
            System.IO.File.Copy(srcPath, targetDir + "Con_" + result);
        }
        //If not existing filename
        else
        {
            //Just copy. Replace bit is false here. So there is no overwiting.
            File.Copy(srcPath, srcPath.Replace(sourceDir, targetDir), false);
        }
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-27
      • 1970-01-01
      • 2012-02-22
      • 2011-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多