2017-03-16 55 views
0

我有一些使用Putty的pscp.exe文件登錄Unix服務器的VBA代碼。我正在使用Windows 7.當用戶名包含@字符時,VBA和Putty的pscp.exe

問題是用戶名包含@字符。如果我使用以下VBA代碼,我無法登錄。

那麼,我該如何替換Username = "[email protected]"才能登錄?

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

Dim Username As String 
Username = "[email protected]" 

Dim Password As String 
Password = "Password2012" 

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

Shell Command, vbNormalFocus 
+0

'命令=​​ 「pscp.exe -sftp -l -o用戶=」 &用戶名和 「-pw」 &Password' http://www.computerhope.com/unix/sftp.htm – cyboashu

+0

@cyboashu如果我使用該代碼,我將被要求輸入'[email protected]的密碼:' – xms

回答

0

爲我工作如下:

Dim Host 
Host = "grid1.example.xxx" 

Dim Username 
Username = "[email protected]" 

Dim Password 
Password = "Password" 

Dim Command 
Command = "pscp.exe -l " & Username & " -pw " & Password & " cmd.txt [email protected]:cmd.txt" 

Set oShell = CreateObject ("WScript.Shell") 
oShell.run "cmd /k " & Command 
+0

如果命令不成功,是否可以獲取ERRORLEVEL值? – xms

+0

請參閱我發佈的其他答案。 –

+0

謝謝!也許我會用那種方式。 – xms

0

對不起,不知道如何在評論部分正確的格式,所以在這裏發帖。嘗試在.bat文件中運行它。

但我確實認爲,用戶名不應該包含主機名,而是要連接到目標%Hostname%中。

@echo off 

set Username="[email protected]" 
set Password=Password 
set Hostname=hostname 

rem or maybe like this 
rem set Username=username 
rem set [email protected] 

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 
相關問題