Topic "Cannot download from FTP via Powershell, but GUI works"

Author Message
david.freer@goldcorp.com
[View user's profile]

Joined: 2014-07-21
Posts: 3
Location: Vancouver
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
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
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.
_________________
Martin Prikryl
david.freer@goldcorp.com
[View user's profile]

Joined: 2014-07-21
Posts: 3
Location: Vancouver
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

Description: (none)

Output.PNG (18.79 KB) Private file

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
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.
_________________
Martin Prikryl
david.freer@goldcorp.com
[View user's profile]

Joined: 2014-07-21
Posts: 3
Location: Vancouver
Thank you, that did the trick, it turned out to be case sensitive was the issue

Thanks again

David
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License