Cannot download from FTP via Powershell, but GUI works

Advertisement

david.freer@goldcorp.com
Joined:
Posts:
3
Location:
Vancouver

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

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,476
Location:
Prague, Czechia

Re: Cannot download from FTP via Powershell, but GUI works

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Also attach a log from a GUI.

Reply with quote

david.freer@goldcorp.com
Joined:
Posts:
3
Location:
Vancouver

Log file as requested

Hello Martin

Please find attached the log file. I simply connected, attempted a download, listed all files and disconnected

A 0 byte file was created in the destination folder (see output.png)

I later connected through the GUI and manually downloaded the file. I changed the username and hostname in the log file

I do hope you can help me, I’m at a loss right now

Thank you

David


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.SessionLogPath = “C:\scripts\ftplog.txt”
$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)
  • ftplog1.txt (40.3 KB, Private file)
  • Output.PNG (18.79 KB, Private file)

Reply with quote

martin
Site Admin
martin avatar

Re: Log file as requested

There's only log from PowerShell. No record of GUI session. Please attach one.

General advice: make sure you have uppercase/lowercase right in a file path.

Reply with quote

Advertisement

You can post new topics in this forum