Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

tkennedy

Re: Wildcards not Working for Download

martin wrote:

While Session.GetFiles DOES support wildcards, the Session.FileExists DOES NOT.

For 5.1.4: Please download new automation pack (winscp514automation2.zip) that fixes the version number mismatch.


Well that makes sense! Thank you, I'll make some changes and see what happens.
martin

Re: Wildcards not Working for Download

While Session.GetFiles DOES support wildcards, the Session.FileExists DOES NOT.

For 5.1.4: Please download new automation pack (winscp514automation2.zip) that fixes the version number mismatch.
tkennedy

Re: Wildcards not Working for Download

Here is a copy of the session log with edits done to remove personal info.

. 2013-02-21 09:09:33.379 --------------------------------------------------------------------------
. 2013-02-21 09:09:33.379 WinSCP Version 5.1.3 (Build 2881) (OS 6.1.7601 Service Pack 1)
. 2013-02-21 09:09:33.379 Configuration: nul
. 2013-02-21 09:09:33.379 Local account: --REMOVED--
. 2013-02-21 09:09:33.379 Working directory: F:\Scripting\
. 2013-02-21 09:09:33.379 Command-line: "F:\Scripting\Utilities\WinSCP\winscp.exe" /xmllog="C:\Users\963258741\AppData\Local\Temp\3\wscp0B7C.0359F034.tmp" /xmlgroups /nointeractiveinput /dotnet=513 /ini=nul /log="F:\Scripting\Daily Logs\SessionLog.log" /console /consoleinstance=_2940_236
. 2013-02-21 09:09:33.379 Time zone: Current: GMT-5, Standard: GMT-5, DST: GMT-4, DST Start: 3/10/2013, DST End: 11/3/2013
. 2013-02-21 09:09:33.379 Login time: Thursday, February 21, 2013 9:09:33 AM
. 2013-02-21 09:09:33.379 --------------------------------------------------------------------------
. 2013-02-21 09:09:33.379 Session name: --REMOVED-- (Ad-Hoc session)
. 2013-02-21 09:09:33.379 Host name: --REMOVED-- (Port: 22)
. 2013-02-21 09:09:33.379 User name: --REMOVED-- (Password: Yes, Key file: No)
. 2013-02-21 09:09:33.379 Tunnel: No
. 2013-02-21 09:09:33.379 Transfer Protocol: SFTP
. 2013-02-21 09:09:33.379 Ping type: -, Ping interval: 30 sec; Timeout: 15 sec
. 2013-02-21 09:09:33.379 Proxy: none
. 2013-02-21 09:09:33.379 SSH protocol version: 2; Compression: No
. 2013-02-21 09:09:33.379 Bypass authentication: No
. 2013-02-21 09:09:33.379 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: No
. 2013-02-21 09:09:33.379 Ciphers: aes,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2013-02-21 09:09:33.379 SSH Bugs: A,A,A,A,A,A,A,A,A,A
. 2013-02-21 09:09:33.379 SFTP Bugs: A,A
. 2013-02-21 09:09:33.379 Return code variable: Autodetect; Lookup user groups: A
. 2013-02-21 09:09:33.379 Shell: default
. 2013-02-21 09:09:33.379 EOL: 0, UTF: 2
. 2013-02-21 09:09:33.379 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes
. 2013-02-21 09:09:33.379 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2013-02-21 09:09:33.379 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2013-02-21 09:09:33.379 Cache directory changes: Yes, Permanent: Yes
. 2013-02-21 09:09:33.379 DST mode: 1
. 2013-02-21 09:09:33.379 --------------------------------------------------------------------------
. 2013-02-21 09:09:33.379 Looking up host --REMOVED--
. 2013-02-21 09:09:33.395 Connecting to --REMOVED-- port 22
. 2013-02-21 09:09:33.410 Server version: SSH-2.0-WS_FTP-SSH_1.1
. 2013-02-21 09:09:33.410 Using SSH protocol version 2
. 2013-02-21 09:09:33.410 We claim version: SSH-2.0-WinSCP_release_5.1.3
. 2013-02-21 09:09:33.426 Using Diffie-Hellman with standard group "group14"
. 2013-02-21 09:09:33.426 Doing Diffie-Hellman key exchange with hash SHA-1
. 2013-02-21 09:09:33.723 Verifying host key rsa2 --REMOVED--
. 2013-02-21 09:09:33.723 Host key matches configured key
. 2013-02-21 09:09:33.723 Host key fingerprint is:
. 2013-02-21 09:09:33.723 ssh-rsa 1024 --REMOVED--
. 2013-02-21 09:09:33.723 Initialised AES-256 CBC client->server encryption
. 2013-02-21 09:09:33.723 Initialised HMAC-SHA1 client->server MAC algorithm
. 2013-02-21 09:09:33.738 Initialised AES-256 CBC server->client encryption
. 2013-02-21 09:09:33.738 Initialised HMAC-SHA1 server->client MAC algorithm
! 2013-02-21 09:09:33.754 Using username --REMOVED--.
. 2013-02-21 09:09:33.817 Prompt (7, SSH password, , &Password: )
. 2013-02-21 09:09:33.817 Using stored password.
. 2013-02-21 09:09:33.817 Sent password
. 2013-02-21 09:09:33.848 Access granted
. 2013-02-21 09:09:33.863 Opened channel for session
. 2013-02-21 09:09:34.051 Started a shell/command
. 2013-02-21 09:09:34.051 --------------------------------------------------------------------------
. 2013-02-21 09:09:34.051 Using SFTP protocol.
. 2013-02-21 09:09:34.051 Doing startup conversation with host.
> 2013-02-21 09:09:34.051 Type: SSH_FXP_INIT, Size: 5, Number: -1
< 2013-02-21 09:09:34.067 Type: SSH_FXP_VERSION, Size: 5, Number: -1
. 2013-02-21 09:09:34.067 SFTP version 4 negotiated.
. 2013-02-21 09:09:34.067 We will use UTF-8 strings when appropriate
. 2013-02-21 09:09:34.067 Getting current directory name.
. 2013-02-21 09:09:34.067 Getting real path for '.'
> 2013-02-21 09:09:34.067 Type: SSH_FXP_REALPATH, Size: 10, Number: 16
< 2013-02-21 09:09:34.223 Type: SSH_FXP_NAME, Size: 40, Number: 16
. 2013-02-21 09:09:34.223 Real path is '/ftpshares/'
. 2013-02-21 09:09:34.223 Startup conversation with host finished.
< 2013-02-21 09:09:34.223 Script: Active session: [1] --REMOVED--
> 2013-02-21 09:09:34.410 Script: ls -- "/ftpshares/Test/"
. 2013-02-21 09:09:34.410 Listing directory "/ftpshares/Test".
> 2013-02-21 09:09:34.410 Type: SSH_FXP_OPENDIR, Size: 32, Number: 267
< 2013-02-21 09:09:34.473 Type: SSH_FXP_HANDLE, Size: 12, Number: 267
> 2013-02-21 09:09:34.473 Type: SSH_FXP_READDIR, Size: 12, Number: 524
< 2013-02-21 09:09:34.567 Type: SSH_FXP_NAME, Size: 7586, Number: 524
> 2013-02-21 09:09:34.567 Type: SSH_FXP_READDIR, Size: 12, Number: 780
< 2013-02-21 09:09:34.582 Type: SSH_FXP_STATUS, Size: 28, Number: 780
< 2013-02-21 09:09:34.582 Status code: 1
> 2013-02-21 09:09:34.582 Type: SSH_FXP_CLOSE, Size: 12, Number: 1028
< 2013-02-21 09:09:34.598 Script: Drwxr-x--- 0 0 Feb 21 3:03:03 2013 .
< 2013-02-21 09:09:34.598 Script: Drwxr-x--- 0 0 Feb 11 5:55:29 2013 ..
< 2013-02-21 09:09:34.598 Script: -rwxr-x--- 0 6222 Feb 18 6:54:04 2013 Monthly_Values_02082013.zip.pgp
< 2013-02-21 09:09:34.598 Script: -rwxr-x--- 0 6213 Feb 18 6:54:07 2013 Weekly_Values_02082013.zip.pgp
> 2013-02-21 09:09:34.817 Script: stat -- "/ftpshares/Test/Monthly_Values_????????.zip.pgp"
. 2013-02-21 09:09:34.817 Listing file "/ftpshares/Test/Monthly_Values_????????.zip.pgp".
> 2013-02-21 09:09:34.817 Type: SSH_FXP_LSTAT, Size: 74, Number: 1287
< 2013-02-21 09:09:34.817 Type: SSH_FXP_STATUS, Size: 17, Number: 1028
. 2013-02-21 09:09:34.817 Discarding reserved response
< 2013-02-21 09:09:34.848 Type: SSH_FXP_STATUS, Size: 94, Number: 1287
< 2013-02-21 09:09:34.848 Status code: 2, Message: 1287, Server: File not found: /ftpshares/Test/Monthly_Values_????????.zip.pgp, Language:
< 2013-02-21 09:09:34.848 Script: Can't get attributes of file '/ftpshares/Test/Monthly_Values_????????.zip.pgp'.
< 2013-02-21 09:09:34.848 Script: No such file or directory.
< 2013-02-21 09:09:34.848 Error code: 2
< 2013-02-21 09:09:34.848 Error message from server: File not found: /ftpshares/Test/Monthly_Values_????????.zip.pgp
< 2013-02-21 09:09:34.848 Request code: 7
. 2013-02-21 09:09:34.848 Script: Failed
> 2013-02-21 09:09:34.957 Script: stat -- "/ftpshares/Test/Weekly_Values_*.zip.pgp"
. 2013-02-21 09:09:34.957 Listing file "/ftpshares/Test/Weekly_Values_*.zip.pgp".
> 2013-02-21 09:09:34.957 Type: SSH_FXP_LSTAT, Size: 66, Number: 1543
< 2013-02-21 09:09:34.988 Type: SSH_FXP_STATUS, Size: 86, Number: 1543
< 2013-02-21 09:09:34.988 Status code: 2, Message: 1543, Server: File not found: /ftpshares/Test/Weekly_Values_*.zip.pgp, Language:
< 2013-02-21 09:09:34.988 Script: Can't get attributes of file '/ftpshares/Test/Weekly_Values_*.zip.pgp'.
< 2013-02-21 09:09:34.988 Script: No such file or directory.
< 2013-02-21 09:09:34.988 Error code: 2
< 2013-02-21 09:09:34.988 Error message from server: File not found: /ftpshares/Test/Weekly_Values_*.zip.pgp
< 2013-02-21 09:09:34.988 Request code: 7
. 2013-02-21 09:09:34.988 Script: Failed
> 2013-02-21 09:09:35.098 Script: exit
. 2013-02-21 09:09:35.098 Script: Exit code: 1
. 2013-02-21 09:09:35.098 Closing connection.
. 2013-02-21 09:09:35.098 Sending special code: 12
. 2013-02-21 09:09:35.098 Sent EOF message



Here is is the relevant download code.

$GetFileMask = @("Monthly_Values_????????.zip.pgp", "Weekly_Values_*.zip.pgp")

$RemotePath = "/ftpshares/Test/"
$dlpath = "F:\DailyTransfers\"


$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Automatic

# Download the files according to the file mask
foreach ($file in $GetFileMask) {              
                 
     if ($Session.FileExists("$RemotePath$file")) {

              # Download the file and throw on any error
              $transferResult = $Session.GetFiles("$RemotePath$file", "$DLPATH$file").Check()
     }



I was not able to get the script to work at all with version 5.1.4. I downloed the the portable 5.1.4 and the .net assembly and copied the basic powershell script from the script exammple page and I get:

The version of F:\Scripting\WinSCP\winscp.exe (5.1.4.0) does not match version of this assembly F:\Scripting\WinSCP\WinSCP.dll (5.2.0.0). You can disable this check using Session.DisableVersionCheck (not recommended).


Please let me know if you need anything else or if I didn't provide everything you need. Thank you for your help.
martin

Re: Wildcards not Working for Download

Can you please post sample of your code along with full session log file (see Session.SessionLogPath). Thanks.

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

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 may email it to me. You will find my address (if you log in) in my forum profile. Please include link back to this topic in your email. Also note in this topic that you have emailed the log.
tkennedy

Wildcards not Working for Download

I'm developing a Powershell script using WinSCP Version 5.1.3 (Build 2881) and I'm having trouble retreiving files when I use wildcards in the file name.

There are two files I'm trying to retreive. One is named something like Monthly_Values_20130201.zip.pgp and the other is Weekly_Values_20130201.zip.pgp. When I use the full file names I am able to retreive the files without any problem. When I use Monthly_Values_*.zip.pgp and Weekly_Values_*.zip.pgp I get:

Status code: 2, Message: 1543, Server: File not found: /path/to/file/Weekly_Values_*.zip.pgp

Status code: 2, Message: 1287, Server: File not found: /path/to/file/Monthly_Values_*.zip.pgp


I also tried Monthly_Values_????????.zip.pgp and Weekly_Values_????????.zip.pgp in the script without success.

If I log in to the site with WinSCP I'm able to use the filters to find the files without any trouble. Any ideas?