Reputation: 199
I want to create a persistent mapped network drive with FTP. I have mounted already an FTP path with the File Explorer of Windows in order to not input the credentials again. What is the solution please?
Here is my code:
New-PSDrive -Persist -Name "X" -PSProvider "FileSystem" -Root "ftp://localhost/"
I have this error:
New-PSDrive: D:\powershell\Untitled-2.ps1:1:1
Line 1
New-PSDrive -Persist -Name "X" -PSProvider "FileSystem" -Root "ftp:// …
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When you use the Persist parameter, the root must be a file system location on a remote computer.
Upvotes: 2
Views: 2959
Reputation: 9133
Let me clarify few of the things.
Mapped network drives are saved in Windows on the local computer. They're persistent, not session-specific,and can be viewed and managed in File Explorer and other tools.
When you scope the command locally, without dot-sourcing, the Persist parameter doesn't persist the creation of a PSDrive beyond the scope in which you run the command. If you run New-PSDrive
inside a script, and you want the new drive to persist indefinitely, you must dot-source the script. For best results, to force a new drive to persist, specify Global as the value of the Scope parameter and include Persist in your command.
The name of the drive must be a letter, such as D
or E
. The value of Root parameter must be a UNC path of a different computer. The PSProvider parameter's value must be FileSystem
.
So technically, you dont need to persist, you just need to specify the -Root
properly:
New-PSDrive -PSProvider filesystem -Root C:\full\path\ -Name anyname
In your case the full path would be an UNC path \\remoteserver\full\path
of FTP
Upvotes: 3