Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vbscript 下载CSV文件的Visual Basic脚本(CSV为空-0字节)_Vbscript_Ftp - Fatal编程技术网

Vbscript 下载CSV文件的Visual Basic脚本(CSV为空-0字节)

Vbscript 下载CSV文件的Visual Basic脚本(CSV为空-0字节),vbscript,ftp,Vbscript,Ftp,我有一个vb脚本可以从URL下载文件-URL是一个ftp站点: 我需要下载下面指定的文件。脚本获取文件,但内容为空-尝试使用ftp站点上的其他CSV文件,但出现相同问题 有人能帮忙吗 HTTPDownload "ftp://ftp.zois.co.uk/pub/jcp/JCP-scrape-2012-04-24.csv", "C:\" Sub HTTPDownload( myURL, myPath ) ' This Sub downloads the FILE specified in myU

我有一个vb脚本可以从URL下载文件-URL是一个ftp站点:

我需要下载下面指定的文件。脚本获取文件,但内容为空-尝试使用ftp站点上的其他CSV文件,但出现相同问题

有人能帮忙吗

HTTPDownload "ftp://ftp.zois.co.uk/pub/jcp/JCP-scrape-2012-04-24.csv", "C:\"

Sub HTTPDownload( myURL, myPath )
' This Sub downloads the FILE specified in myURL to the path specified in myPath.
'
' myURL must always end with a file name
' myPath may be a directory or a file name; in either case the directory must exist
'
 ' Written by Rob van der Woude
' http://www.robvanderwoude.com
'
    ' Based on a script found on the Thai Visa forum
' http://www.thaivisa.com/forum/index.php?showtopic=21832

' Standard housekeeping
Dim i, objFile, objFSO, objHTTP, strFile, strMsg
Const ForReading = 1, ForWriting = 2, ForAppending = 8

' Create a File System Object
Set objFSO = CreateObject( "Scripting.FileSystemObject" )

' Check if the specified target file or folder exists,
' and build the fully qualified path of the target file
If objFSO.FolderExists( myPath ) Then
    strFile = objFSO.BuildPath( myPath, Mid( myURL, InStrRev( myURL, "/" ) + 1 ) )
ElseIf objFSO.FolderExists( Left( myPath, InStrRev( myPath, "\" ) - 1 ) ) Then
    strFile = myPath
Else
    WScript.Echo "ERROR: Target folder not found."
    Exit Sub
End If

' Create or open the target file
Set objFile = objFSO.OpenTextFile( strFile, ForWriting, True )

' Create an HTTP object
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

' Download the specified URL
objHTTP.Open "GET", myURL, False
objHTTP.Send

' Write the downloaded byte stream to the target file
For i = 1 To LenB( objHTTP.ResponseBody )
    objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
Next

' Close the target file
objFile.Close( )
End Sub

该代码用于从HTTP下载。FTP不是HTTP。FTP确实有一个get命令,但如果没有其他命令,端口几乎肯定是不同的,因为没有指定端口,它几乎肯定使用80作为HTTP,而FTP使用21作为默认值。是一个使用ftp的类似示例。可能有其他/更好的FTP组件,而不是它所使用的,但这是问题的根源。还请注意,它并不是真正获取您的文件,它只是创建了一个从未写入的文件。

谢谢-有ftp程序来同步它