Upload mit VBA über sFTP & FTP, Protokollausgaben zur Fehlererkennung

Ich habe den folgenden Code geschrieben, um zu versuchen, einen über FTP und einen über SFTP auf zwei verschiedene Server hochzuladen.

Ich würde gerne wissen, ob es eine bessere Möglichkeit zum Hochladen über SFTP gibt, da die aktuelle Methode, wie ich sie habe, den FTP-Fehler nicht auslöst, wenn sie auf irgendeinem Teil fehlschlägt.

Ich vermute, ein Workaround und etwas, das ich haben möchte, ist, dass beide die Ausgabe in eine Textdatei protokollieren. Daran kann ich manuell erkennen, was der Fehler war, und wenn ich ein einfaches Leseprotokoll einrichten möchte, Fehler überprüfen , wenn x y tun ...

        On Error GoTo Err_FTPFile

        ' UPLOAD FIRST FILE VIA FTP

        'Build up the necessary parameters
        sHost = "ftp.server.com"
        sUser = "[email protected]"
        sPass = "password"
        sSrc = """" + Environ("TEMP") + "\" + file + ".txt" + """"
        sDest = "/remote/folder/"

        'Write the FTP commands to a file
        iFNum = FreeFile
        sFTPCmds1 = Environ("TEMP") & "\" & "FTPCmd1.tmp"
        Open sFTPCmds1 For Output As #iFNum
            Print #iFNum, "ftp"
            Print #iFNum, "open " & sHost
            Print #iFNum, sUser
            Print #iFNum, sPass
            Print #iFNum, "cd " & sDest
            Print #iFNum, "put " & sSrc
            Print #iFNum, "disconnect"
            Print #iFNum, "bye"
        Close #iFNum

        'Upload the file
        Shell Environ("WINDIR") & "\System32\ftp.exe -s:" & sFTPCmds1
        Application.Wait (Now + TimeValue("0:00:10"))


        ' UPLOAD SECOND FILE VIA SFTP

        'Build up the necessary parameters
        sFTPDetails = "C:\psftp.exe -b C:\commands.tmp [email protected] -pw password"
        sSrc = """" + Environ("TEMP") + "\" + file + ".txt" + """"
        sDest = "/remote/folder/"

        'Write the FTP commands to a file
        iFNum = FreeFile
        sFTPCmds2 = sFolder & "\" & "commands.tmp"
        Open sFTPCmds2 For Output As #iFNum
            Print #iFNum, "cd " & sDest
            Print #iFNum, "put " & sSrc
            Print #iFNum, "quit"
            Print #iFNum, "bye"
        Close #iFNum

        'Upload the file
        Call Shell(sFTPDetails, vbNormalFocus)
        Application.Wait (Now + TimeValue("0:00:10"))

Exit_FTPFile:
        On Error Resume Next
        Close #iFNum

        'Delete the temp FTP command file
        Kill sFTPCmds1
        Kill sFTPCmds2
        Kill Environ("TEMP") + file + ".txt"

        GoTo ContinuePoint

Err_FTPFile:
        Shell "C:\FailPushBullet.exe"
        MsgBox Err.Number & " - " & Err.Description & " Failed.", vbOKOnly, "Error"
        GoTo ContinuePoint

ContinuePoint:
' Do stuff

Ich möchte, dass das SFTP unten genauso funktioniert und funktioniert wie das FTP von oben.

Ich habe Folgendes versucht und dies läuft:

    sClient = "C:\psftp.exe"
    sArgs = "[email protected] -pw passexample -b C:\commands.tmp"
    sFull = sClient & " " & sArgs

    sSrc = """" + Environ("TEMP") + "\" + "test" + ".txt" + """"
    sDest = "folder"

    'Write the FTP commands to a text file
    iFNum = FreeFile
    sFTPCmds = "C:\" & "commands.tmp"
    Open sFTPCmds For Output As #iFNum
        Print #iFNum, "cd " & sDest
        Print #iFNum, "put " & sSrc
        Print #iFNum, "quit"
        Print #iFNum, "bye"
    Close #iFNum

    'Upload the file
    Call Shell(sFull, vbNormalFocus)

Aber wenn ich die sArgs auf @ ändesArgs = "[email protected] -pw passexample -b C:\commands.tmp 1> log.txt" es läuft nicht, es wird nur geschlossen, ohne etwas zu tun. Ich dachte1> log.txt soll die Ausgabe in eine Datei legen

Antworten auf die Frage(2)

Ihre Antwort auf die Frage