Reputation: 47
I hope you and your family are doing well- I've been struggling with this error that I really don't understand.
This is the PowerShell script that I created to upload files to a ftp server using PSFTP
$path="C:\Users\jhosef.cardich\Desktop\sol\psftp.exe"
$comd1= "lcd C:\Users\jhosef.cardich\Desktop\sol\"
$upload_result = ($comd1) | & $path -pw $pass "$user@$hst" 2> $
$comd2="put myfile,txt"
$upload_result+= $comd2 | & $path -pw $pass "$user@$hst" 2> $
$upload_result | Out-File -FilePath "C:\Users\jhosef.cardich\Desktop\sol\sftp.txt" -Append
"DateTime Stamp - Upload: $(Get-Date)" | Out-File -FilePath "C:\Users\jhosef.cardich\Desktop\sol\sftp.txt" -Append
and this the output I get every time I run my code: (I would like you to focus on the second line)
Remote working directory is /download
psftp> psftp: unknown command "ktop\sol\"
psftp> quit
Remote working directory is /download
psftp> quit
DateTime Stamp - Upload: 11/18/2020 21:21:49
As you can see, I do not understand why in the second line I get the error "unknown command" and it seems that psftp only detects a part of the string where I have defined the path. I also tried this implementation but I'm getting the same error (Call multiple commands from powershell e.g psftp).
Upvotes: 0
Views: 842
Reputation: 47
Update on this: The problem was due to some configurations on the server in which the script that contains the putty command was being executed.
Exactly, it was a problem with the windows trusted hosts that for some reason we don't know how the FTP host that we are using to connect putty, was removed from that list.
We've noticed that when we tried to open a connection with Filezilla, it prompted a notification asking us to trust and add the FTP domain to the windows trusted host list. When we accept that, suddenly the script was working fine again. Very strange, but my advice is to use WinScp instead of putty. Thanks.
Upvotes: 1