I'm new to PowerShell so forgive me for what others may find a simple question. I need to create a process to get various files from an external ftp site and I would like to use a PowerShell script to do the job. I have tried various sample codes but all have failed because the server actually has folders with spaces in the name (e.g. My File is Here) So the mapping would look like this: ftp://ftp.servername.com/ClientsFiles/ProgramsNotes/myVIEW/My File is Here/hereItIs.txt
Could someone help me address the problem with the name space problem? Thank you in advanced.
No need to apologize, we all started somewhere!
You typically would URL escape a space, which would be like "Program%20Files". But it depends an awful lot on exactly what you're using to accomplish FTP. PowerShell doesn't have a built-in FTP client, so whatever you're using would dictate how to escape the filename. For example, if you're just invoking an ftp:// URL, then Windows will launch your default client (likely IE), and it'd usually escape the URL for you.
Thanks for the responds. I am actually look to set up a windows schedule task and have files copied from a third party ftp server to our server so we can then load the data into the database. Is this doable with PowerShell scripting?
I understand the use of "%20" and I had tried that in various ways went referencing the ftp url but it failed each time.
PowerShell does not include a native ability to talk to an FTP server. There might be something FTP-related in the underlying .NET Framework you could use (I'm not sure).
In the past I've done this by scripting the native Windows FTP command-line client. You could launch that from within PowerShell, but do so just as easily from Cmd.exe or Task Scheduler. It's not a PowerShell-specific feature.
I believe "/n software" still offers an add-in for PowerShell that includes FTP functionality (I think it's still called PowerCmdlets).
That said, scripting the native FTP client can make it difficult to deal with failures and other problems. Most of my customers who need to do what you're doing eventually look into a Managed File Transfer (MFT) solution (Ipswitch is one company that makes them).
Actually, just did a quick search and found http://msdn.microsoft.com/en-us/library/system.net.webrequestmethods.ftp.aspx, which is what you may have been trying. That's the WebRequest object, which seems to be able to speak FTP. If it isn't taking your URL, and doing URL-style encoding isn't working, then it might just not like the remote server (spaces in filenames or folder names technically isn't allowed in the FTP protocol). But the WebRequest object isn't PowerShell per-se; if that's what you're using and nobody else chimes in here, you might consider asking on StackOverflow.com. That's more oriented to .NET development (amongst other languages) and you're more likely to find someone who has done what you're trying to do.
I was starting to wonder that. I want to thank you very much for your time. I have come to the same conclusion. As for the FTP protocol, I don't understand how someone would actually build their servers in such a fashion. Oh well.
And thanks for the link, I will look it over but I think I will just build it the way I have built it in the past. I just thought there would be a more secure way of doing.
You must be logged in to reply to this topic.