0

I have some VBA code which is using Putty's pscp.exe file for logging on Unix server. I am using Windows 7.

The problem is that the username includes a @ character. I am not able to login if I use the following VBA code.

So, how should I replace Username = "user@example.xxx" to be able to login?

Dim Host As String
Host = "grid1.example.xxx"

Dim Username As String
Username = "user@example.xxx"

Dim Password As String
Password = "Password2012"

Dim Command As String
Command = "pscp.exe -sftp -l " & Username & " -pw " & Password

Shell Command, vbNormalFocus
xms
  • 429
  • 5
  • 24
  • `Command = "pscp.exe -sftp -l -o User=" & Username & " -pw " & Password` http://www.computerhope.com/unix/sftp.htm – cyboashu Mar 16 '17 at 23:12
  • @cyboashu If I use that code, I will be asked for `-o@grid1.example.xxx's password:` – xms Mar 16 '17 at 23:30

2 Answers2

0

Worked for me as below:

Dim Host
Host = "grid1.example.xxx"

Dim Username
Username = "username@host"

Dim Password
Password = "Password"

Dim Command
Command = "pscp.exe -l " & Username & " -pw " & Password & " cmd.txt username@host:cmd.txt"

Set oShell = CreateObject ("WScript.Shell") 
oShell.run "cmd /k " & Command
access_granted
  • 1,807
  • 20
  • 25
0

Sorry, don't know how to format correctly in the comments section, so posting here. Try to run it in a .bat file instead.

I do think, however, the username should not include the hostname, and rather get concatenated in the target %Hostname%.

@echo off

set Username="username@hostname"
set Password=Password
set Hostname=hostname

rem or maybe like this
rem set Username=username
rem set Hostname=username@hostname

pscp32.exe -sftp -l %Username% -pw %Password% cmd.txt %Hostname%:cmd.txt

if errorlevel 2 goto Err2
if errorlevel 1 goto Err1

echo success!
goto :EOF

:Err2
echo error 2
goto :EOF


:Err1
echo error 1
goto :EOF
access_granted
  • 1,807
  • 20
  • 25