在Windows中通过FTP复制文件夹

时间:2016-04-07 10:19:52

标签: windows ftp

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

  • 我无法压缩此文件夹。
  • 我也试过使用mget*,但它会复制所有文件中的所有文件 文件夹但没有创建文件夹结构。
  • 我无法使用TAR命令,因为提示符显示"无效命令"。

2 个答案:

答案 0 :(得分:3)

Windows command-line FTP client, the ftp.exe, does not support recursive directory transfers.


You have to use a 3rd party FTP client for that.

For example with WinSCP FTP client, you can use a batch-file like:

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

It will automatically download all files and subfolders in the /folder.

For details, see WinSCP guide to automating file transfers from FTP server. There's also a guide for converting Windows ftp.exe script to WinSCP.

(I'm the author of WinSCP)

答案 1 :(得分:-1)

目标目录是一个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);
    }

}