1

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:J13@Files8.cyberlynk.net/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.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
qwerty
  • 887
  • 11
  • 33
  • *"I access my server using this path `fs01\Reporting\KGP\File History`"* - Shouldn't there be \\ at the front? - Show us how you can access your server using this path! + Show us how your WinSCP script with this path looks and the exact error message that the script produces! – Martin Prikryl Apr 26 '17 at 19:33
  • @MartinPrikryl https://i.stack.imgur.com/IBrp1.jpg.. here is my output. I access my server using \\fs01\Reporting\KGP\File History ... I edited my question. Sorry about that. – qwerty Apr 26 '17 at 19:43
  • @MartinPrikryl I know i have to connect to this server before i transfer any files.. but i have no idea how to do that. The host name is fs01 for the server I want to transfer the files to. – qwerty Apr 26 '17 at 19:48
  • Do you have to "connect" really? What does this do? `dir "\\fs01\Reporting\KGP\File History"` (in `cmd.exe`) – Martin Prikryl Apr 26 '17 at 20:06
  • If you have to connect/authenticate really, then your question is duplicate of [How to give credentials in a batch script that copies files to a network location?](http://stackoverflow.com/questions/3854026/how-to-give-credentials-in-a-batch-script-that-copies-files-to-a-network-locatio) – Martin Prikryl Apr 26 '17 at 20:08
  • @MartinPrikryl Basically i want to do the same process that i was doing earlier, when i was downloading files from ftp server to my local machine. Except now i want to transfer them to the other server. – qwerty Apr 26 '17 at 20:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/142771/discussion-between-rahul-and-martin-prikryl). – qwerty Apr 26 '17 at 20:30

1 Answers1

1

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:J13@Files8.cyberlynk.net/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:

Community
  • 1
  • 1
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • The get is used to get the files that were in ftp server having today's date and the rm is used to remove all files except the ones that came in today. – qwerty Apr 27 '17 at 13:58
  • @Rahul OK, if that's what you want, the code is correct. Except that one of the boundaries should include `=` (i.e. `>` + `<=` or `>=` + `<`), otherwise you may miss some file. – Martin Prikryl Apr 27 '17 at 14:01
  • Anyway, did my answer help? – Martin Prikryl Apr 27 '17 at 14:01
  • Umm... your code seems to be downloading the file but i am not sure where to. I am trying to transfer it to my file server, but its showing a couple of errors. – qwerty Apr 27 '17 at 14:23
  • https://i.stack.imgur.com/PtzbB.jpg here is the batch file output. I am not sure how to generate a log file. I'll be posting that in a bit. The code I am using is given below : https://i.stack.imgur.com/rlMrL.jpg – qwerty Apr 27 '17 at 14:41
  • Log file link is given below : https://1drv.ms/u/s!AqM8VOWpB4Ona9OAWkuDeOvDsjM Thank You so much! – qwerty Apr 27 '17 at 16:16
  • So what, if you add `"lls ""\\fs01\Reporting\test KGP\File History\""" ^` to command list (before `exit`)? What does it display? And if you add `dir "\\fs01\Reporting\test KGP\File History\"` after `winscp.com` call. What does it display? + Why do you use `net use`, [if you claimed](http://chat.stackoverflow.com/transcript/message/36824879#36824879) that `dir` works straight away - The `net user` gives you an error anyway, did you notice? – Martin Prikryl Apr 27 '17 at 17:32
  • Hey, i got it to work! Thanks a lot!! :D You have helped me with all the questions related to winSCP, really appreciate it! – qwerty Apr 27 '17 at 18:09
  • I had to use net use in order to be able to access that directory through the script. – qwerty Apr 27 '17 at 18:12