-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set-SFTPFile : Object reference not set to an instance of an object. #294
Comments
Ould you try set-sftpitem? That cmdlet is deprecated and replaced by sftpitem
…Sent from my iPhone
On Oct 27, 2019, at 12:07 AM, TLA50 ***@***.***> wrote:
I am trying to upload a csv file to a sftp site, but keep getting this error. "Set-SFTPFile : Object reference not set to an instance of an object."
My code is below.
Set the credentials
$Password = ConvertTo-SecureString 'BlahBlah' -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ('UserNAME', $Password)
Set local file path, SFTP path, and the backup location path which I assume is an SMB path
$FilePath = "C:\Temp\MY_CSV_FILE.csv"
$SftpPath = '/'
$SmbPath = 'C:\temp\Backup'
Set the IP of the SFTP server
$SftpIp = 'sftp.place.co.uk'
Load the Posh-SSH module
Import-Module Posh-SSH
Establish the SFTP connection
$ThisSession = New-SSHSession -ComputerName $SftpIp -AcceptKey $Credential
Upload the file to the SFTP path
Set-SFTPFile -SessionId ($ThisSession).SessionId -LocalFile $FilePath -RemotePath $SftpPath
#Disconnect all SFTP Sessions
Get-SFTPSession | % { Remove-SFTPSession -SessionId ($_.SessionId) }
Copy the file to the SMB location
Copy-Item -Path $FilePath -Destination $SmbPath
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I am experiencing the same issue. For both Set-SFTPFile and Set-SFTPItem.
This could be linked to issue #37. |
What is the remote server? Need to be able to replicate the issue
…Sent from my iPhone
On Feb 27, 2020, at 8:15 AM, dbrennand ***@***.***> wrote:
I am experiencing the same issue. For both Set-SFTPFile and Set-SFTPItem.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
It looks like the function isn't working correctly when passing a I fixed my issue by creating a SFTPSession using Here is my working code:
$Test = New-SFTPSession -ComputerName "Someip" -AcceptKey -KeyFile "somekeyfilepath" -Credential $Credential -Verbose:($PSBoundParameters["Verbose"] -eq $true) -ErrorAction "Stop"
New-SFTPItem -SFTPSession $Test -Path "Path to file" -ItemType "File"
Set-SFTPItem -SFTPSession $Test -Destination "somedestination" -Path "somefile" -Force -Verbose:($PSBoundParameters["Verbose"] -eq $true) -ErrorAction "Stop" |
Could I be missing something? this is against a Ubuntu system running Open-SSH. |
Try using |
Should be New-SFTPSession and not New-SSHSession, SSH and SFTP are different sessions
|
Ok, but the documentation to me implies that |
SessionId is generic 🤷♂️ Further down you can see the object type is sftp. Can I close the ticket?
…Sent from my iPhone
On Mar 3, 2020, at 5:36 AM, dbrennand ***@***.***> wrote:
Ok, but the documentation to me implies that New-SSHSession can be used. It just says to use -SessionId. I interpreted this as being able to use New-SSHSession.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I am trying to upload a csv file to a sftp site, but keep getting this error. "Set-SFTPFile : Object reference not set to an instance of an object."
My code is below.
Set the credentials
$Password = ConvertTo-SecureString 'BlahBlah' -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ('UserNAME', $Password)
Set local file path, SFTP path, and the backup location path which I assume is an SMB path
$FilePath = "C:\Temp\MY_CSV_FILE.csv"
$SftpPath = '/'
$SmbPath = 'C:\temp\Backup'
Set the IP of the SFTP server
$SftpIp = 'sftp.place.co.uk'
Load the Posh-SSH module
Import-Module Posh-SSH
Establish the SFTP connection
$ThisSession = New-SSHSession -ComputerName $SftpIp -AcceptKey $Credential
Upload the file to the SFTP path
Set-SFTPFile -SessionId ($ThisSession).SessionId -LocalFile $FilePath -RemotePath $SftpPath
#Disconnect all SFTP Sessions
Get-SFTPSession | % { Remove-SFTPSession -SessionId ($_.SessionId) }
Copy the file to the SMB location
Copy-Item -Path $FilePath -Destination $SmbPath
The text was updated successfully, but these errors were encountered: