I've got a PowerShell script that uploads files to an FTP. It does this by building a script called ftp.txt, retrieving a list of files that have been created in a directory, and adding a "put" line for each file to the script. It then calls winscp with /console and /S flags to upload the files. That part works great.

I also need to clear the destination FTP before uploading files. This part doesn't work so well. According to WinSCP documentation, I should be able to do "rm *.csv" to clear all .csv files on the destination FTP. This doesn't work, though: I get Error deleting file/Permission denied.

The FTP user has appropriate delete permissions, and I can even go in through Windows Explorer to the FTP, highlight all the files and delete them. I can also delete individual files over the command line with WinSCP using "rm [filename]" - it's just the wildcard thing that doesn't work.

I'd like to find an alternate way of clearing these files. Any ideas? Just needs to be fully automated and clear the directory of all .csv files. I'm not married to using WinSCP for this if there's a better way of doing it.

link|improve this question
(Disclaimer: I know nothing about PowerShell.) The wildcard might expand to all the csv files in your current local directory, not on the FTP server. Sort of why tar cvzf foo.tgz -C /some/dir * also doesn't work as one would expect. – Daniel Beck Jun 8 '11 at 19:58
I don't think that's the case... the wildcard is being read directly into WinSCP through the console. PowerShell is only involved in building the script. – SuperNES Jun 8 '11 at 20:24
Can you successfully remove one file using rm when you specify it? "rm somefile.csv" Also, you might try "quote rm *.csv". Quote is an ftp command that says tell the ftp server to do "this". – uSlackr Jun 8 '11 at 20:46
Not on Windows to try this, but in pseudo-code, try this idea: foreach (filename) in (get-filenames) | delete-file. The idea is to retrieve a list of files and using a foreach loop, delete every file in that list. – Joe Internet Jun 8 '11 at 20:55
are you issuing the rm *.csv command from your script file or is that run separately? If it's from the script file powershell shouldn't be involved at all. Have you checked the logs on the server to see which files it's trying to remove? – Pär Björklund Jun 8 '11 at 21:10
feedback

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
or
required, but never shown

Browse other questions tagged or ask your own question.