Parent folder on SFTP being automatically created in local folder

Advertisement

GCDeveloper
Joined:
Posts:
1
Location:
Utah

Parent folder on SFTP being automatically created in local folder

How do I stop the parent folder of a file being downloaded from SFTP being created locally? Here is a snippet of my code.
var sFtppath = "./Solutions/Inbound/";
var sNetpath = @"\\Solutions\Inbound\";
...
using (_oSession)
{
    TransferOptions transferOptions = new TransferOptions
    {
        FileMask = "*.txt",
        TransferMode = TransferMode.Automatic
    };
 
    try
    {
        TransferOperationResult operationResult = 
            _oSession.GetFiles(
               sFtppath,
               sNetpath + "*",
               false,
               transferOptions);
 
        operationResult.Check();
 
        foreach(TransferEventArgs transfer in operationResult.Transfers)
        {                       
            var tmp = transfer.FileName;
            _oSession.MoveFile(tmp, tmp + ".processed");
        }
...
The result I get looks like: /Solutions/Inbound/1579952381-20220902-022723.txt downloaded to \\Solutions\Inbound\Inbound\1579952381-20220902-022723.txt

The second Inbound in the destination is automatically created. How do I stop this? Doesn't make sense to me since my destination variable is explicitly clear, i.e.
sNetpath = @"\\Solutions\Inbound\"

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,884
Location:
Prague, Czechia

Re: Parent folder on SFTP being automatically created in local folder

It should be: sFtppath + "*"
See https://winscp.net/eng/docs/library_session_getfiles#remotepath

Or even easier, use Session.GetFilesToDirectory:
TransferOperationResult operationResult = 
    _oSession.GetFilesToDirectory(
       sFtppath,
       sNetpath,
       options: transferOptions);

See also https://winscp.net/eng/docs/faq_script_vs_gui#inputs

Reply with quote

Advertisement

You can post new topics in this forum