Vbscript e位于 ”“在http://creativecommons.org/licenses/by-nc/2.5/ . 可能不会 “未经明确书面同意,不得用于商业目的 “来自NateRice.com 常量OpenAsDefault=-2 常数FailIfNotExist=0 常数ForReading=1 写入常数=2 脚本模糊 脚本外壳的颜色 Dim sOriginalWorkingDirectory Dim sFTPScript 暗sFTPTemp Dim sFTPTempFile 暗灯管 模糊的脚本 暗淡的结果 暗淡sCmd 暗淡的苏特 LOG_Write“MISC_FTPDownload called at:”&现在 pscript的集合fso=CreateObject(“Scripting.FileSystemObject”) 脚本Shell的集合=CreateObject(“WScript.Shell”) sRemotePath=修剪(sRemotePath) sLocalPath=修剪(sLocalPath) '------------路径检查--------- '这里我们将检查远程路径,如果它包含 '然后我们需要添加引号以确保 “它解析正确。 如果InStr(sRemotePath,“”>0,则 如果左(sRemotePath,1)“”,右(sRemotePath,1)“”,则 sRemotePath=“”&sRemotePath&“” 如果结束 如果结束 '检查以确保远程路径是正确的 ”“通过了。如果为空,则传递一个“\” 如果Len(sRemotePath)=0,则 '请注意,没有预先检查 '远程路径已完成。如果它在某些情况下不存在 ”“原因。可能会出现意外的结果。 sRemotePath=“\” 如果结束 '如果本地路径为空。通电 “工作目录。 如果Len(sLocalPath)=0,则 sLocalPath=oFTPScriptShell.CurrentDirectory 如果结束 如果不是oFTPScriptFSO.FolderExists(sLocalPath),则 '找不到目标 sError=“错误:未找到本地文件夹。” 日志记录 杂项下载=错误 退出功能 如果结束 sOriginalWorkingDirectory=oFTPScriptShell.CurrentDirectory oFTPScriptShell.CurrentDirectory=sLocalPath '----------结束路径检查--------- '为ftp命令生成输入文件 sFTPScript=sFTPScript&“选项批处理打开”&vbCRLF sFTPScript=sFTPScript&“选项确认关闭”&vbCrLf sFTPScript=sFTPScript&“选项传输二进制文件”&vbCrLf sFTPScript=sFTPScript&“打开sftp://”&sUsername&“:”&sPassword&“@”&sSite&vbCrLf sFTPScript=sFTPScript&“cd”&sRemotePath&vbCrLf sFTPScript=sFTPScript&“get”&sRemoteFile&vbCRLF sFTPScript=sFTPScript&“关闭”和vbCrLf sFTPScript=sFTPScript&“退出”和vbCrLf 日志_写入“FTP文件的脚本:”&vbNewLine&sFTPScript sFTPTemp=oFTPScriptShell.ExpandEnvironmentStrings(“%TEMP%”) sFTPTempFile=sFTPTemp&“\”oFTPScriptFSO.GetTempName 日志_写入“FTP输入文件存储在:”&sFTPTempFile '写入ftp命令的输入文件 '到一个临时文件。 Set oFTPScript=oFTPScriptFSO.CreateTextFile(sFTPTempFile,True) oFTPScript.WriteLine(sFTPScript) oFTPScript。关闭 脚本集=无 sCmd=“”C:\Program Files\WinSCP\WinSCP.com”“-script=“&sFTPTempFile 杂项RunCmd,南部,sError 日志写入源 Wscript.Sleep 1000 '清除用于输入sftp的临时文件 oFTPScriptFSO.DeleteFile(sFTPTempFile) '检查转移结果。 如果sError=“”和InStr(sOut,“二进制”)>0和InStr(sOut,“100%”)>0,则 杂项下载=真 其他的 sError=“错误:”&sError 日志记录 杂项下载=错误 如果结束 pscriptfso的集合=无 脚本shell集=无 端函数
代理必须充当此操作的代理。(用于数据传输的协议)旨在防止这种情况。在您添加Vbscript e位于 ”“在http://creativecommons.org/licenses/by-nc/2.5/ . 可能不会 “未经明确书面同意,不得用于商业目的 “来自NateRice.com 常量OpenAsDefault=-2 常数FailIfNotExist=0 常数ForReading=1 写入常数=2 脚本模糊 脚本外壳的颜色 Dim sOriginalWorkingDirectory Dim sFTPScript 暗sFTPTemp Dim sFTPTempFile 暗灯管 模糊的脚本 暗淡的结果 暗淡sCmd 暗淡的苏特 LOG_Write“MISC_FTPDownload called at:”&现在 pscript的集合fso=CreateObject(“Scripting.FileSystemObject”) 脚本Shell的集合=CreateObject(“WScript.Shell”) sRemotePath=修剪(sRemotePath) sLocalPath=修剪(sLocalPath) '------------路径检查--------- '这里我们将检查远程路径,如果它包含 '然后我们需要添加引号以确保 “它解析正确。 如果InStr(sRemotePath,“”>0,则 如果左(sRemotePath,1)“”,右(sRemotePath,1)“”,则 sRemotePath=“”&sRemotePath&“” 如果结束 如果结束 '检查以确保远程路径是正确的 ”“通过了。如果为空,则传递一个“\” 如果Len(sRemotePath)=0,则 '请注意,没有预先检查 '远程路径已完成。如果它在某些情况下不存在 ”“原因。可能会出现意外的结果。 sRemotePath=“\” 如果结束 '如果本地路径为空。通电 “工作目录。 如果Len(sLocalPath)=0,则 sLocalPath=oFTPScriptShell.CurrentDirectory 如果结束 如果不是oFTPScriptFSO.FolderExists(sLocalPath),则 '找不到目标 sError=“错误:未找到本地文件夹。” 日志记录 杂项下载=错误 退出功能 如果结束 sOriginalWorkingDirectory=oFTPScriptShell.CurrentDirectory oFTPScriptShell.CurrentDirectory=sLocalPath '----------结束路径检查--------- '为ftp命令生成输入文件 sFTPScript=sFTPScript&“选项批处理打开”&vbCRLF sFTPScript=sFTPScript&“选项确认关闭”&vbCrLf sFTPScript=sFTPScript&“选项传输二进制文件”&vbCrLf sFTPScript=sFTPScript&“打开sftp://”&sUsername&“:”&sPassword&“@”&sSite&vbCrLf sFTPScript=sFTPScript&“cd”&sRemotePath&vbCrLf sFTPScript=sFTPScript&“get”&sRemoteFile&vbCRLF sFTPScript=sFTPScript&“关闭”和vbCrLf sFTPScript=sFTPScript&“退出”和vbCrLf 日志_写入“FTP文件的脚本:”&vbNewLine&sFTPScript sFTPTemp=oFTPScriptShell.ExpandEnvironmentStrings(“%TEMP%”) sFTPTempFile=sFTPTemp&“\”oFTPScriptFSO.GetTempName 日志_写入“FTP输入文件存储在:”&sFTPTempFile '写入ftp命令的输入文件 '到一个临时文件。 Set oFTPScript=oFTPScriptFSO.CreateTextFile(sFTPTempFile,True) oFTPScript.WriteLine(sFTPScript) oFTPScript。关闭 脚本集=无 sCmd=“”C:\Program Files\WinSCP\WinSCP.com”“-script=“&sFTPTempFile 杂项RunCmd,南部,sError 日志写入源 Wscript.Sleep 1000 '清除用于输入sftp的临时文件 oFTPScriptFSO.DeleteFile(sFTPTempFile) '检查转移结果。 如果sError=“”和InStr(sOut,“二进制”)>0和InStr(sOut,“100%”)>0,则 杂项下载=真 其他的 sError=“错误:”&sError 日志记录 杂项下载=错误 如果结束 pscriptfso的集合=无 脚本shell集=无 端函数,vbscript,winscp,Vbscript,Winscp,代理必须充当此操作的代理。(用于数据传输的协议)旨在防止这种情况。在您添加open命令的行中: sFTPScript=sFTPScript&“打开sftp://”&sUsername&“:”&sPassword&“@”&sSite&vbCrLf 。。。添加-rawsettings开关,然后添加与您的代理类型相关的选项: 例如: sFTPScript=…&“-rawsettings ProxyMethod=3 ProxyHost=proxy”&vbCrLf 有关详细信息,请参阅: 要使用代理
open
命令的行中:
sFTPScript=sFTPScript&“打开sftp://”&sUsername&“:”&sPassword&“@”&sSite&vbCrLf
。。。添加-rawsettings
开关,然后添加与您的代理类型相关的选项:
例如:
sFTPScript=…&“-rawsettings ProxyMethod=3 ProxyHost=proxy”&vbCrLf
有关详细信息,请参阅:要使用代理,首先使用WINSCP GUI进行连接,指定代理详细信息。这将在配置文件(与winscp.com位于同一目录)中添加代理的详细信息,然后它就可以工作了。然后,您可以将此配置文件的路径传递给执行进程任务,并调用WINSCP.com可执行文件。请完成最后一句话。您好,demongolem,感谢您指出这一点。我在另一个网站上发布了同一个问题的答案,在复制文本时,最后一行没有正确粘贴
'###########################################################################
'# Function: MISC_FTPUpload
'#
'# Description:
'# Uses the FSO object to FTP a file to a remote server
'#
'# Parameters:
'# (in) sSite - The site to FTP to
'# (in) sUsername - The username to log in with
'# (in) sPassword - The password to log in with
'# (in) sLocalFile - The Locally stored file to FTP to the remote server
'# (in) sRemotePath - The path to store the file in, on the remote server
'#
'# (out) - sError - The error output
'#
'# Return:
'# True - File successfully sent
'# False - File not successfully sent
'###########################################################################
Function MISC_FTPUpload(byVal sSite, byVal sUsername, byVal sPassword, byVal sLocalFile, byVal sRemotePath, byRef sError)
'This script is provided under the Creative Commons license located
'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not
'be used for commercial purposes with out the expressed written consent
'of NateRice.com
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
Const ForWriting = 2
Dim oFTPScriptFSO
Dim oFTPScriptShell
Dim sOriginalWorkingDirectory
Dim sFTPScript
Dim sFTPTemp
Dim bRetCode
Dim sFTPTempFile
Dim oFTPScript
Dim sResults
Dim sOut
Dim sCmd
LOG_Write "MISC_FTPUpload called at: " & Now
Set oFTPScriptFSO = CreateObject("Scripting.FileSystemObject")
Set oFTPScriptShell = CreateObject("WScript.Shell")
sRemotePath = Trim(sRemotePath)
sLocalFile = Trim(sLocalFile)
'----------Path Checks---------
'Here we will check the path, if it contains
'spaces then we need to add quotes to ensure
'it parses correctly.
If InStr(sRemotePath, " ") > 0 Then
If Left(sRemotePath, 1) <> """" And Right(sRemotePath, 1) <> """" Then
sRemotePath = """" & sRemotePath & """"
End If
End If
If InStr(sLocalFile, " ") > 0 Then
If Left(sLocalFile, 1) <> """" And Right(sLocalFile, 1) <> """" Then
sLocalFile = """" & sLocalFile & """"
End If
End If
'Check to ensure that a remote path was
'passed. If it's blank then pass a "\"
If Len(sRemotePath) = 0 Then
'Please note that no premptive checking of the
'remote path is done. If it does not exist for some
'reason, Unexpected results may occur.
sRemotePath = "\"
End If
'Check the local path and file to ensure
'that either the a file that exists was
'passed or a wildcard was passed.
If InStr(sLocalFile, "*") Then
If InStr(sLocalFile, " ") Then
sError = "Error: Wildcard uploads do not work if the path contains a space." & vbNewLine & "This is a limitation of the Microsoft FTP client."
LOG_Write sError
MISC_FTPUpload = False
Exit Function
End If
ElseIf Len(sLocalFile) = 0 Or Not oFTPScriptFSO.FileExists(sLocalFile) Then
'nothing to upload
sError = "Error: File Not Found."
LOG_Write sError
MISC_FTPUpload = False
Exit Function
End If
'--------END Path Checks---------
'build input file for ftp command
sFTPScript = sFTPScript & "option batch on" & vbCRLF
sFTPScript = sFTPScript & "option confirm off"& vbCrLf
sFTPScript = sFTPScript & "option transfer binary" & vbCrLf
sFTPScript = sFTPScript & "open sftp://" & sUsername & ":" & sPassword & "@" & sSite & vbCrLf
sFTPScript = sFTPScript & "cd " & sRemotePath & vbCrLf
sFTPScript = sFTPScript & "put " & sLocalFile & vbCRLF
sFTPScript = sFTPScript & "close" & vbCrLf
sFTPScript = sFTPScript & "exit" & vbCrLf
LOG_Write "Script for FTP File: " & vbNewLine & sFTPScript
sFTPTemp = oFTPScriptShell.ExpandEnvironmentStrings("%TEMP%")
sFTPTempFile = sFTPTemp & "\" & oFTPScriptFSO.GetTempName
LOG_Write "FTP Input file stored at: " & sFTPTempFile
'Write the input file for the ftp command
'to a temporary file.
Set oFTPScript = oFTPScriptFSO.CreateTextFile(sFTPTempFile, True)
oFTPScript.WriteLine(sFTPScript)
oFTPScript.Close
Set oFTPScript = Nothing
sCmd = """C:\Program Files\WinSCP\WinSCP.com"" -script=" & sFTPTempFile
MISC_RunCmd sCmd, sOut, sError
LOG_Write sOut
Wscript.Sleep 1000
' Get rid of temp file used for input to sftp
oFTPScriptFSO.DeleteFile(sFTPTempFile)
'Check results of transfer.
If sError = "" And InStr(sOut, "binary") >0 And InStr(sOut, "100%") >0 Then
MISC_FTPUpload = True
Else
sError = "Error: " & sError
LOG_Write sError
MISC_FTPUpload = False
End If
Set oFTPScriptFSO = Nothing
Set oFTPScriptShell = Nothing
End Function
'###########################################################################
'# Function: MISC_FTPDownload
'#
'# Description:
'# Uses the FSO object to FTP a file from a remote server
'#
'# Parameters:
'# (in) sSite - The site to FTP from
'# (in) sUsername - The username to log in with
'# (in) sPassword - The password to log in with
'# (in) sLocalPath - The path to store the file in, on the local drive
'# (in) sLocalPath - The path to get the file from, on the remote drive
'# (in) sRemoteFile - The remotely stored file to FTP to the local drive
'#
'# (out) - sError - The error output
'#
'# Return:
'# True - File successfully retrieved
'# False - File not successfully retrieved
'###########################################################################
Function MISC_FTPDownload(byVal sSite, byVal sUsername, byVal sPassword, byVal sLocalPath, byVal sRemotePath, byVal sRemoteFile, byRef sError)
'This script is provided under the Creative Commons license located
'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not
'be used for commercial purposes with out the expressed written consent
'of NateRice.com
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
Const ForWriting = 2
Dim oFTPScriptFSO
Dim oFTPScriptShell
Dim sOriginalWorkingDirectory
Dim sFTPScript
Dim sFTPTemp
Dim sFTPTempFile
Dim bRetCode
Dim oFTPScript
Dim sResults
Dim sCmd
Dim sOut
LOG_Write "MISC_FTPDownload called at: " & Now
Set oFTPScriptFSO = CreateObject("Scripting.FileSystemObject")
Set oFTPScriptShell = CreateObject("WScript.Shell")
sRemotePath = Trim(sRemotePath)
sLocalPath = Trim(sLocalPath)
'----------Path Checks---------
'Here we will check the remote path, if it contains
'spaces then we need to add quotes to ensure
'it parses correctly.
If InStr(sRemotePath, " ") > 0 Then
If Left(sRemotePath, 1) <> """" And Right(sRemotePath, 1) <> """" Then
sRemotePath = """" & sRemotePath & """"
End If
End If
'Check to ensure that a remote path was
'passed. If it's blank then pass a "\"
If Len(sRemotePath) = 0 Then
'Please note that no premptive checking of the
'remote path is done. If it does not exist for some
'reason. Unexpected results may occur.
sRemotePath = "\"
End If
'If the local path was blank. Pass the current
'working direcory.
If Len(sLocalPath) = 0 Then
sLocalPath = oFTPScriptShell.CurrentDirectory
End If
If Not oFTPScriptFSO.FolderExists(sLocalPath) Then
'destination not found
sError = "Error: Local Folder Not Found."
LOG_Write sError
MISC_FTPDownload = False
Exit Function
End If
sOriginalWorkingDirectory = oFTPScriptShell.CurrentDirectory
oFTPScriptShell.CurrentDirectory = sLocalPath
'--------END Path Checks---------
'build input file for ftp command
sFTPScript = sFTPScript & "option batch on" & vbCRLF
sFTPScript = sFTPScript & "option confirm off"& vbCrLf
sFTPScript = sFTPScript & "option transfer binary" & vbCrLf
sFTPScript = sFTPScript & "open sftp://" & sUsername & ":" & sPassword & "@" & sSite & vbCrLf
sFTPScript = sFTPScript & "cd " & sRemotePath & vbCrLf
sFTPScript = sFTPScript & "get " & sRemoteFile & vbCRLF
sFTPScript = sFTPScript & "close" & vbCrLf
sFTPScript = sFTPScript & "exit" & vbCrLf
LOG_Write "Script for FTP File: " & vbNewLine & sFTPScript
sFTPTemp = oFTPScriptShell.ExpandEnvironmentStrings("%TEMP%")
sFTPTempFile = sFTPTemp & "\" & oFTPScriptFSO.GetTempName
LOG_Write "FTP Input file stored at: " & sFTPTempFile
'Write the input file for the ftp command
'to a temporary file.
Set oFTPScript = oFTPScriptFSO.CreateTextFile(sFTPTempFile, True)
oFTPScript.WriteLine(sFTPScript)
oFTPScript.Close
Set oFTPScript = Nothing
sCmd = """C:\Program Files\WinSCP\WinSCP.com"" -script=" & sFTPTempFile
MISC_RunCmd sCmd, sOut, sError
LOG_Write sOut
Wscript.Sleep 1000
' Get rid of temp file used for input to sftp
oFTPScriptFSO.DeleteFile(sFTPTempFile)
'Check results of transfer.
If sError = "" And InStr(sOut, "binary") >0 And InStr(sOut, "100%") >0 Then
MISC_FTPDownload = True
Else
sError = "Error: " & sError
LOG_Write sError
MISC_FTPDownload = False
End If
Set oFTPScriptFSO = Nothing
Set oFTPScriptShell = Nothing
End Function