Hi all.I needed to write a script to upload file to a FTP server and from what I read, the PSFTP module was recommended. So I downloaded and installed it. I then proceeded to write my script and that's when I ran into my problem which I can't seem to figure out where it lies, but I have a credentials issue when using the Add-FTPItem.So I wrote another (simpler) script to test and have the same issue in the following code.
$FtpServer = 'ftp.site.com'
$User = 'userid'
$Password = ConvertTo-SecureString 'password' -AsPlainText -Force
$FtpCredentials = New-Object System.Management.Automation.PSCredential ($User, $Password)
Set-FTPConnection -Credentials $FtpCredentials -Server $FtpServer -Session MyFtpSession ` -UsePassive
$FtpSession = Get-FTPConnection -Session MyFtpSession
$FileSize = 0
$FileSize = Get-FTPItemSize -Path "/import.xxx" -Session $FtpSessionGet-FTPItem -Path "/import.xxx" -LocalPath "c:\temp" -Session $FtpSession -OverwriteAdd-FTPItem -Path "/" -LocalPath "c:\temp\test.txt" -Session $FtpSession
Both the Get-FTPItemSize and Get-FTPItem function calls work properly, but the Add-FTPItem generates the following error messages:
Exception setting "Credentials": "Value cannot be null.
Parameter name: value"
At C:\Documents and Settings\lamothed\My Documents\WindowsPowerShell\Modules\PSFTP \Add-FTPItem.ps1:150 char:18
+ $Request. <<<< Credentials = $CurrentSession.Credentials
+ CategoryInfo : InvalidOperation: (:) , RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
Exception calling "GetRequestStream" with "0" argument(s): "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."
At F:\home\dlamothe\Upload.ps1:11 char:12
+ Add-FTPItem <<<< -Path "/" -LocalPath "c:\temp\test.txt" -Session $FtpSession
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Add-FTPItem
I've tried different ftp sites (both internal and external) to make sure it wasn't the site. I've tested this code in both version 4 (on Windows 7) and version 2 (on Windows 7, XP mode) with identical results.Any help would be appreciated.