Search code examples
batch-fileftpwinscpuncshared-directory

Using batch file and WinSCP to download files from the FTP server to file server (shared folder)


I am using the following code to transfer files from my FTP server to my local machine which works fine.

"C:\Program Files (x86)\WinSCP\WinSCP.com" /command ^
    "open ftp://rnandipati:[email protected]/kgptel/" ^
    "lcd ""C:\\rnandipati\KGP\File History""" ^
    "get  *.xls>1D" ^
    "rm *.xls<1D" ^
    "exit"

Now, I access my server using this path

\\fs01\\Reporting\KGP\File History

When I put this path in place of my local directory path, it shows an error that the system could not find the file specified and error changing directory.

Thanks.


Solution

  • A UNC path cannot be a working directory in Windows.

    But you can use it as a target path in the get command:

    get *.xls>1D "\\fs01\Reporting\KGP\File History\"
    

    A full command for a batch file will be:

    "C:\Program Files (x86)\WinSCP\WinSCP.com" /command ^
        "open ftp://rnandipati:[email protected]/kgptel/" ^
        "get *.xls>1D ""\\fs01\Reporting\KGP\File History\""" ^
        "rm *.xls<1D" ^
        "exit"
    

    (not that I understand a logic of the get *.xls>1D and rm *.xls<1D)

    For a similar question, see Get file from FTP server and copy it to UNC directory.


    If you need to authenticate to the file server, see: