Excel VBA - WinSCP 명령줄에 공백이 있는 변수 경로 전달 (Excel VBA - Passing a variable path with spaces to WinSCP command-line)


문제 설명

Excel VBA ‑ WinSCP 명령줄에 공백이 있는 변수 경로 전달 (Excel VBA ‑ Passing a variable path with spaces to WinSCP command‑line)

내 Excel 책(vba 코드를 처음으로 작성함) 중 하나에 이 게시물 하단에 코드가 있습니다. 여기의 목표는 사용자가 다음을 수행할 수 있도록 하는 것입니다.

  1. 임시 파일 이름으로 MXLight 소프트웨어를 사용하여 비디오 인코딩 시작
  2. 현재 비디오에 있는 사람이 있는 셀 선택
  3. 비디오 인코딩을 중지하고, 임시 파일의 이름을 변경하고, 특정 폴더로 이동하고, WinSCP 소프트웨어를 통해 FTP를 통해 업로드하고, 녹색으로 표시하고, 한 셀 아래로 이동합니다.

그래서 이벤트 기간 동안:

  1. Sub StartMXL인 버튼 1을 누르세요.
  2. 셀을 강조 표시합니다.
  3. Sub StartMXL인 버튼 2를 누릅니다. StopAndProcess

제 질문은 다음과 같습니다.

1) 무엇보다도, 전체(중지 및 처리) 버튼은 업로드 기능이 실패하여 작동하지 않습니다. 왜냐하면 어떻게 winscp 명령이 참조된 변수를 사용하고 그 단어를 사용하려고 하지 않는지 알 수 없기 때문입니다. Sub Upload 아래에 있는 코드를 확인하고 시도했을 때의 로그 파일은 다음과 같습니다.

1 . 2015‑11‑12 17:53:18.490 Connected
2 . 2015‑11‑12 17:53:18.490 Using FTP protocol.
3 . 2015‑11‑12 17:53:18.490 Doing startup conversation with host.
4 > 2015‑11‑12 17:53:18.491 PWD
5 < 2015‑11‑12 17:53:18.520 257 "/" is the current directory
6 . 2015‑11‑12 17:53:18.520 Getting current directory name.
7 . 2015‑11‑12 17:53:18.520 Startup conversation with host finished.
8 < 2015‑11‑12 17:53:18.520 Script: Active session: [1] ftp1934501@ftp.kaltura.com
9 > 2015‑11‑12 17:53:18.520 Script: put RealFile
10. 2015‑11‑12 17:53:18.520 Copying 1 files/directories to remote directory "/"
11. 2015‑11‑12 17:53:18.520   PrTime: Yes; PrRO: No; Rght: rw‑r‑‑r‑‑; PrR: No (No); FnCs: N; RIC: 0100; Resume: S (102400); CalcS: No; Mask: 
12. 2015‑11‑12 17:53:18.520   TM: B; ClAr: No; RemEOF: No; RemBOM: No; CPS: 0; NewerOnly: No; InclM: ; ResumeL: 0
13. 2015‑11‑12 17:53:18.520   AscM: *.*html; *.htm; *.txt; *.php; *.php3; *.cgi; *.c; *.cpp; *.h; *.pas; *.bas; *.tex; *.pl; *.js; .htaccess; *.xtml; *.css; *.cfg; *.ini; *.sh; *.xml
14* 2015‑11‑12 17:53:18.520 (EOSError) System Error.  Code: 2.
15* 2015‑11‑12 17:53:18.520 The system cannot find the file specified

9번째 줄에서 파일 이름과 폴더 구조가 있는 변수의 내용을 사용하는 대신 "RealFile"이라는 파일을 문자 그대로 업로드하려고 하는 것을 볼 수 있습니다. 그 변수는 이름을 변경하고 이동할 때와 같이 코드의 다른 부분에서 작동합니다.

어떤 아이디어가 있습니까?

전체에 대한 전체 코드는 다음과 같습니다.

Public Sub StartMXL()
    Dim MXLapp As String
    MXLapp = "C:\1a7j42w\MXLight‑2‑4‑0\MXLight.exe"
    Shell (MXLapp & " record=on"), vbNormalNoFocus
    AppActivate Application.Caption
End Sub
‑‑‑
Public Sub StopMXL()
    Dim MXLapp As String
    MXLapp = "C:\1a7j42w\MXLight‑2‑4‑0\MXLight.exe"
    Shell (MXLapp & " record=off"), vbNormalNoFocus
    AppActivate Application.Caption
End Sub
‑‑‑
Sub ChooseRootDir()
    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "Please choose a folder"
        .AllowMultiSelect = False
        If .Show = ‑1 Then Sheets("rawdata").Range("I1").Value = .SelectedItems(1)
    End With
End Sub
‑‑‑
Public Sub RenameAndMove()
    Dim TempFile As String
    Dim RealFile As String

    If Len(Dir(Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value, vbDirectory)) = 0 Then
        MkDir Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value
    End If
        If Len(Dir(Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value, vbDirectory)) = 0 Then
        MkDir Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value
    End If
        If Len(Dir(Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value & "\" & Sheets("rawdata").Range("L1").Value, vbDirectory)) = 0 Then
        MkDir Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value & "\" & Sheets("rawdata").Range("L1").Value
    End If

    TempFile = Sheets("rawdata").Range("I1").Value & "\tempfile\spiderman.TS"
    RealFile = Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value & "\" & Sheets("rawdata").Range("L1").Value & "\" & ActiveCell.Value & ".TS"

    Name TempFile As RealFile
End Sub
‑‑‑
Public Sub Upload()
    Dim RealFile As String
    Dim TempFile As String

    RealFile = Sheets("rawdata").Range("I1").Value & "\" & Sheets("rawdata").Range("J1").Value & "\" & Sheets("rawdata").Range("K1").Value & "\" & Sheets("rawdata").Range("L1").Value & "\" & ActiveCell.Value & ".TS"
    TempFile = "C:\1a7j42w\MXLight‑2‑4‑0\recordings\tempfile\spiderman.TS"

    Call Shell( _
    "C:\1a7j42w\WinSCP\WinSCP.com /log=C:\1a7j42w\WinSCP\excel.log /command " & _
    """open ftp://ftp1934501:da7Mc4Fr@ftp.kaltura.com/"" " & _
    """put RealFile"" " & _
    """exit""")
End Sub
‑‑‑
Sub StopAndProcess()
    Call StopMXL
    Call RenameAndMove
    Call Upload
    Selection.Interior.ColorIndex = 4
    ActiveCell.Offset(1, 0).Select
End Sub

## 참조 솔루션 #### 방법 1:

In WinSCP script, you want:

put "path with space"

See Command parameters with spaces.


On WinSCP command line, you have to enclose each command to a double quotes and double all double quotes in the command itself:

"put ""path with space"""

See WinSCP command‑line syntax.


In VB you need to enclose the string in double quotes and double all double quotes in the string itself:

"""put """"path with space"""""" "

And to replace the path with a variable, substitute the path with space with " & RealFile & ".

This gives you:

"""put """"" & RealFile & """"""" "

(by JarmerMartin Prikryl)

참조 문서

  1. Excel VBA ‑ Passing a variable path with spaces to WinSCP command‑line (CC BY‑SA 2.5/3.0/4.0)

#vba #FTP #winscp #excel






관련 질문

열에 문자열이 포함된 경우 열 번호 나열 (List column numbers if columns contain string)

SpinButton SpinUp 또는 SpinDown 새로 고침 (Refreshing SpinButton SpinUp or SpinDown)

변수를 사용하여 Excel VBA에서 3차원 배열 요소에 액세스 (Use variables to access 3 dimensional array elements in Excel VBA)

TODAY() 함수와 월 1일을 기준으로 범위 이동 (Moving a range based on TODAY() function and first of the month)

ALV 레이아웃의 표시된 모든 열을 제거하는 방법 (How to remove all displayed columns of ALV layout)

셀에 입력한 msoShapeOval은 MsoShapeType으로 선언된 변수의 값이 될 수 없습니다. (msoShapeOval entered in cell not allowed to be value for variable declared as MsoShapeType)

Excel VBA의 세로 열에 여러 json을 생성하는 방법은 무엇입니까? (How to generate multiple json in vertical column in Excel VBA?)

공개 함수의 VBA 런타임 오류 -2147319767(80028029) (VBA Run-time error -2147319767 (80028029) in Public Function)

알 수 없는 수의 문자를 패턴 일치시키는 방법 (How to Pattern Match an Unknown Number of Characters)

Excel VBA 파일이 열려 있는지 확인 기능 (Excel VBA Check if File is open function)

ActiveCell..Offset(-1,0)=을 사용하는 If/And/Then/Else 문의 VBA 문제= (VBA Issue with If/And/Then/Else statement using ActiveCell..Offset(-1,0)=)

VBA 런타임 오류 '1004': 응용 프로그램 정의 또는 개체 정의 오류" 설정 셀 내용 (VBA Runtime Error '1004': Application-defined or Object-defined error" setting cell contents)







코멘트