Vishal5364
Vishal5364

Reputation: 293

Copy folders through FTP in Windows

I have a Windows 2012 server where I am trying to copy a folder through FTP. The folder contains multiple folders inside it and the size is around 12 GB. What command can be used to copy the whole tree structure including all the folders and files inside it.

Upvotes: 2

Views: 20753

Answers (2)

Martin Prikryl
Martin Prikryl

Reputation: 202721

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:[email protected]/" ^
    "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)

Upvotes: 4

Dev Try
Dev Try

Reputation: 211

The target dir is a zip file. You can copy the full zip file into the ftp server using below code.

//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);
    }

}

Upvotes: -2

Related Questions