Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

Julia

How to get list of folders when using batch

Hi,
I am using "batch" and I can't get my head around how can I pull list of subfolders from parent folder on FTP site. Here is the script I use. Thanks a lot =)
string ftpDetails = "ftp://xxx@xxx.org.uk:xxxxxx@ftp.xxxxxx.co.uk:990 -implicit";
 
string batchFileName = @"\\xxx\xxx\xxx\Julia\TEST_Images\Transfer\batch.txt";
string logFileName = @"\\xxx\xxx\xxx\Julia\TEST_Images\Transfer\ftp.log";
 
string sourceFolder = "/xxx/xxx/Export/Images"; //this is parent FTP folder   
string destinationFolder = @"\\xxx\xxx\xxx\Julia\TEST_Images\Transfer\Live\"; //this is On-Premise folder
 
string batch =
    "option batch on" + Environment.NewLine +
    "option confirm off" + Environment.NewLine +
    "open " + ftpDetails + Environment.NewLine +
    "cd " + sourceFolder + Environment.NewLine +
    "option transfer binary" + Environment.NewLine +
 
    //"get " + sourceFolder + Environment.NewLine + //no luck
    //"get " + sourceFolder + "/" + Environment.NewLine + //no luck
    //"get " + sourceFolder + "/*" + Environment.NewLine + //no luck
    //"get " + sourceFolder + "//*" + Environment.NewLine + //no luck
 
    "close" + Environment.NewLine +
    "close" + Environment.NewLine +
    "exit" + Environment.NewLine
    ;
File.WriteAllText(batchFileName, batch);
 
string arg = "\"/script=" + batchFileName + "\" /log=\"" + logFileName + "\"";
 
ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(@"\\care-sql-prd01\winscp$\WinSCP.com", arg);
Process p = new System.Diagnostics.Process();
p.StartInfo = info;
p.Start();
p.WaitForExit();