Cannot download from FTP via Powershell, but GUI works
Hello
I’m having a strange issue with PowerShell WinSCP.net and FTP, but ok downloading via the GUI (using WinSCP 5.5.4)
My error message "Copying files from remote side failed"
I have written code to connect to a SFTP server and download files daily, this works fine. I then connect to a FTP server with a slightly modified code (FTP instead of SFTP for the protocol) but have the error “Copying files from remote side failed”, when I look in the session output I see ‘Permission denied’ for the file I am trying to download. Connecting to the FTP server works fine via the GUI
I can see the file with a ListDirectory command
-rw-rw---- 0 int_lstorage int_lstorage 41283 Jul 30 20:35 Test.doc
The filename is created on the destination drive with a 0 byte file length
I then connect through the WinSCP GUI and can download the file ok via FTP
I looked for sample code for Powershell and FTP, but couldn’t find any examples, I hope it’s not a coding issue on my part.
Example Code:-
$SessionOptions = New-Object WinSCP.SessionOptions
$SessionOptions.Protocol = [WinSCP.Protocol]::FTP
$SessionOptions.HostName = “192.168.32.32”
$SessionOptions.UserName = "xxxx"
$SessionOptions.Password = "1234"
$Session = New-Object WinSCP.Session
$Session.Open($SessionOptions)
$OutputMessage = $Session.Output
$TransferOptions = New-Object WinSCP.TransferOptions
$TransferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$SourceDir = "/OUT/test.doc"
$DestinationDir = "F:\Concur\Downloads(Encrypted)\test.doc"
$TransferResult = $Session.GetFiles($SourceDir, $DestinationDir, $False,$TransferOptions)
PS F:\Concur> $TransferResult
Transfers Failures IsSuccess
--------- -------- ---------
"/OUT/test.doc" {WinSCP.SessionRemoteException: Error transferring file '... False
PS F:\Concur> $TransferResult.Failures
Error transferring file '"/OUT/test.doc'.
PS F:\Concur> $Session
ExecutablePath :
AdditionalExecutableArguments :
DefaultConfiguration : True
DisableVersionCheck : False
IniFilePath :
ReconnectTime : 10675199.02:48:05.4775807
DebugLogPath :
SessionLogPath :
XmlLogPath : C:\Users\admin.df.ca\AppData\Local\Temp\2\wscp0F0C.00EC709A.tmp
Timeout : 00:01:00
Output : {winscp> option batch on, batch on , winscp> option confirm off, confirm off ...}
Opened : True
UnderlyingSystemType : WinSCP.Session
$TransferOptions
PreserveTimestamp : True
FilePermissions :
TransferMode : Binary
FileMask :
ResumeSupport : default
$Session.Output
get -nopermissions -preservetime -transfer="binary" -- "/OUT/Test.doc" "F:\Concur\Downloads(Encrypted)\Test.doc"
Test.doc | 0 B | 0.0 KiB/s | binary | 0%
Error transferring file '/OUT/Test.doc.
Copying files from remote side failed.
Test.doc: Permission denied.
(A)bort, (R)etry, (S)kip, Ski(p) all: Abort
Note: I changed the filename, credentials, etc for security
I’m having a strange issue with PowerShell WinSCP.net and FTP, but ok downloading via the GUI (using WinSCP 5.5.4)
My error message "Copying files from remote side failed"
I have written code to connect to a SFTP server and download files daily, this works fine. I then connect to a FTP server with a slightly modified code (FTP instead of SFTP for the protocol) but have the error “Copying files from remote side failed”, when I look in the session output I see ‘Permission denied’ for the file I am trying to download. Connecting to the FTP server works fine via the GUI
I can see the file with a ListDirectory command
-rw-rw---- 0 int_lstorage int_lstorage 41283 Jul 30 20:35 Test.doc
The filename is created on the destination drive with a 0 byte file length
I then connect through the WinSCP GUI and can download the file ok via FTP
I looked for sample code for Powershell and FTP, but couldn’t find any examples, I hope it’s not a coding issue on my part.
Example Code:-
$SessionOptions = New-Object WinSCP.SessionOptions
$SessionOptions.Protocol = [WinSCP.Protocol]::FTP
$SessionOptions.HostName = “192.168.32.32”
$SessionOptions.UserName = "xxxx"
$SessionOptions.Password = "1234"
$Session = New-Object WinSCP.Session
$Session.Open($SessionOptions)
$OutputMessage = $Session.Output
$TransferOptions = New-Object WinSCP.TransferOptions
$TransferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$SourceDir = "/OUT/test.doc"
$DestinationDir = "F:\Concur\Downloads(Encrypted)\test.doc"
$TransferResult = $Session.GetFiles($SourceDir, $DestinationDir, $False,$TransferOptions)
PS F:\Concur> $TransferResult
Transfers Failures IsSuccess
--------- -------- ---------
"/OUT/test.doc" {WinSCP.SessionRemoteException: Error transferring file '... False
PS F:\Concur> $TransferResult.Failures
Error transferring file '"/OUT/test.doc'.
PS F:\Concur> $Session
ExecutablePath :
AdditionalExecutableArguments :
DefaultConfiguration : True
DisableVersionCheck : False
IniFilePath :
ReconnectTime : 10675199.02:48:05.4775807
DebugLogPath :
SessionLogPath :
XmlLogPath : C:\Users\admin.df.ca\AppData\Local\Temp\2\wscp0F0C.00EC709A.tmp
Timeout : 00:01:00
Output : {winscp> option batch on, batch on , winscp> option confirm off, confirm off ...}
Opened : True
UnderlyingSystemType : WinSCP.Session
$TransferOptions
PreserveTimestamp : True
FilePermissions :
TransferMode : Binary
FileMask :
ResumeSupport : default
$Session.Output
get -nopermissions -preservetime -transfer="binary" -- "/OUT/Test.doc" "F:\Concur\Downloads(Encrypted)\Test.doc"
Test.doc | 0 B | 0.0 KiB/s | binary | 0%
Error transferring file '/OUT/Test.doc.
Copying files from remote side failed.
Test.doc: Permission denied.
(A)bort, (R)etry, (S)kip, Ski(p) all: Abort
Note: I changed the filename, credentials, etc for security