Why I cannot connect/transfer using script, when I can using GUI (or vice versa)?
Advertisement
Common Problems
There are three common reasons why a script does not work, when a connectivity is otherwise possible
Environment
You run script from a different environment (under a different account/service; with a different configuration) than the GUI.
See another FAQ: My script works fine when executed manually, but fails or hangs when run by Windows Scheduler, SSIS or other automation service. What am I doing wrong? (Although it covers a different topic, its recommendations are valid for this case as well).
Configuration
You have your session configured differently in the script and in the GUI.
- Use a Generate Session URL/Code command to avoid common mistakes in manually typed URL’s or code; and to make sure all the settings from your GUI configuration is used in the script.
A common problem is special characters in some part of the session URL (typically a password or a username).
Further, some characters have special meaning in string literals in programming languages. If your password (or other credential) contains such special character, it needs to be escaped using the rules of the language. Notably in PowerShell, a dollar sign has special meaning in double-quoted string. Code generated by WinSCP escapes these too. - Passphrase to an SSH private key is not a password, you need to specify it using
-passphrase
switch, not in a password part of the session URL. - With WebDAV and S3 protocols, it is possible that you do not have an access to the root folder (bucket list in S3).
Paths
You use different paths in the script than in the GUI.
- Always make sure you that use the exact paths that you see on the label above the file panel in the GUI. Use Copy Path to Clipboard command to avoid typing errors.
- Common mistake is using paths that are relative to the home folder as absolute paths. For example, when there’s
data
folder in your/home/user
folder, you cannot refer to the folder as/data
. Either use an absolute path/home/user/data
(recommended) or relative pathdata
. - Remote paths are case sensitive. So
Data
is not the same asdata
.
Advertisement
Source and Destination Inputs
Commands in scripting (like put
and get
) and some methods in .NET assembly (like Session.GetFiles
and Session.PutFiles
) do not take mere paths as inputs. The source input is expected to be a path terminated by a slash (a backslash when uploading) and followed by a file mask. Similarly the destination input is expected to be a path also terminated by a slash (a backslash when downloading) followed by an optional operation mask. As a simple example, a command to upload all files in scripting should be like:
put C:\source\path\* /destination/path/
Similarly in .NET assembly:
$session.PutFiles("C:\source\path\*", "/destination/path/").Check()
The trailing \*
in the source path and the /
in the destination path both matter. Read documentation of respective scripting commands or .NET assembly methods for details. In .NET assembly, in many cases, it’s easier to use more specific methods like Session.PutFileToDirectory
, Session.PutFilesToDirectory
,Session.GetFileToDirectory
or Session.GetFilesToDirectory
, as they do not have that strict interpretation of the inputs.
Logging
You can also enable a session logging both in the GUI (on Logging page of Preferences dialog) and the script (using a command-line parameter /log
) and compare the logs to find out what is different. Use a command-line parameter /loglevel=*
to enable a password logging and check if a correct password is used.
If you decide to seek a help, make sure you provide both complete logs, when describing your issue.
Further Reading
- More generic article Why WinSCP does not work in a new environment (operating system, machine, user account, network), when it works for me in a different environment already?.
- Troubleshooting scripting/automation issues
- Debugging transfer task running in Windows Scheduler, SSIS, or another automation service.