Skip to content
This repository has been archived by the owner on Feb 6, 2022. It is now read-only.

Getting a New-PSDrive fails with error #1

Closed
tklein opened this issue Aug 29, 2017 · 4 comments
Closed

Getting a New-PSDrive fails with error #1

tklein opened this issue Aug 29, 2017 · 4 comments

Comments

@tklein
Copy link

tklein commented Aug 29, 2017

I started using your PsFTPProvider and was able to compile w/o any errors. When creating a new PS-Drive I get the following error:

PS C:\[...]\PsFtpProvider\bin\Debug\net46\publish> New-PSDrive -PSProvider PsFtp -Name 'MyFTPSite' -Hostname 'ftp.rz.uni-wuerzburg.de' -Port 21 -Root /
New-PSDrive : Object reference not set to an instance of an object.
At line:1 char:1
+ New-PSDrive -PSProvider PsFtp -Name 'MyFTPSite' -Hostname 'ftp.rz.uni ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-PSDrive], NullReferenceException
    + FullyQualifiedErrorId : NewDriveProviderException,Microsoft.PowerShell.Commands.NewPSDriveCommand

For testing purposes I'm using a publicly available FTP server with anonymous access.

The provider is loaded

PS C:\[...]\PsFtpProvider\bin\Debug\net46\publish> Get-PSProvider

Name                 Capabilities                                      Drives
----                 ------------                                      ------
Registry             ShouldProcess, Transactions                       {HKLM, HKCU}
Alias                ShouldProcess                                     {Alias}
Environment          ShouldProcess                                     {Env}
FileSystem           Filter, ShouldProcess, Credentials                {C, A, D, H...}
Function             ShouldProcess                                     {Function}
Variable             ShouldProcess                                     {Variable}
PsFtp                Credentials                                       {}

Do you have any clue what goes wrong here? If you need any further information pls let me know...

@Arnavion
Copy link
Owner

Arnavion commented Aug 29, 2017

In a7314dc I changed the code to not check if drive.Credential is PSCredential.Empty and instead just cast it to NetworkCredential using the existing operator.

But this operator throws an NRE if the PSCredential is PSCredential.Empty (_userName is null), which is the case in your command.

System.Management.Automation.dll!System.Management.Automation.PSCredential.SplitUserDomain(string input, out string user, out string domain)
System.Management.Automation.dll!System.Management.Automation.PSCredential.IsValidUserName(string input, out string user, out string domain)
System.Management.Automation.dll!System.Management.Automation.PSCredential.GetNetworkCredential()
PsFtpProvider.dll!PsFtpProvider.FtpProvider.NewDrive(System.Management.Automation.PSDriveInfo drive) Line 174	C#

@Arnavion
Copy link
Owner

I've filed PowerShell/PowerShell#4696

Meanwhile I'll revert that commit.

@Arnavion
Copy link
Owner

Arnavion commented Aug 29, 2017

Done.

Note that that FTP server does need a username and password, so you'll need to use the -Credential parameter like the README shows (username anonymous, empty password). Eg

$ New-PSDrive -PSProvider PsFtp -Name 'MyFTPSite' -Hostname 'ftp.rz.uni-wuerzburg.de' -Port 21 -Root / -Credential ([pscredential]::new('anonymous', [securestring]::new()))

$ dir MyFTPSite:

Mode       Modified            Size Name
----       --------            ---- ----
drwxr-xr-x 01/21/2017 11:36:35    0 MIRROR
drwxr-x--x 07/24/2017 07:52:43    0 tmp
...

@tklein
Copy link
Author

tklein commented Aug 29, 2017

Wow, that was quick, and works flawlessly...

Thanks a lot! 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants