2009-08-20 108 views
1

無論如何,我可以創建一個小的exe或批處理文件來設置Windows中的一個新的「我的網絡地點」?它的FTP站點,如果有任何區別。以編程方式爲FTP站點添加「我的網絡位置」?

XP將主要成爲目標機器,但如果我能找到一些能在Vista上工作的東西,那太棒了。

+0

您正在嘗試創建將連接到FTP服務器的腳本? – jgallant 2009-08-20 12:46:30

+0

不,我正在嘗試創建一個腳本,它會自動將網絡地址添加到FTP站點。然後用戶可以使用Windows資源管理器拖放文件。 – Alex 2009-08-20 16:07:28

回答

0

我寫了這個腳本來使用代理服務器連接到FTP。您可以根據自己的需求進行調整。它會提示輸入您正在嘗試訪問的文件名和文件夾。只要切斷你不需要的代碼,你就應該很好走。

您還需要更改FTP服務器名稱變量。快樂編碼:

Option Explicit 

Dim objShell, strFTPScriptFileName, strFile2Get 
Dim strLocalFolderName, strFTPServerName, strLoginID 
Dim strPassword, strFTPServerFolder, strFileToGet, returnCode 


'Customize code here to fit your needs 
strFTPServerName = "proxy.prv" 
strLocalFolderName = "" 
strLoginID = "" 
strPassword = "" 
strFTPServerFolder = "" 
strFileToGet = "" 




strLocalFolderName = GetLocalFolder() 
strLoginID = InputBox("Enter FTP Username: ", "Enter FTP Username", "[email protected]_FTP_Host") 
strPassword = InputBox("Enter FTP Password: ", "Enter FTP Password", "[email protected]_FTP_Host") 
strFTPServerFolder = InputBox("Enter FTP folder that you want to access: ", "Enter FTP Folder", "/") 
strFileToGet = InputBox("Enter the filename located on the FTP that you want to retrieve: ", "Enter FTP file", "*.*") 

if strLoginID = "" then 
    WScript.Echo "You must specify a Login ID for this script to work" 
    WScript.Quit() 
end if 

if strPassword = "" then 
    WScript.Echo "You must specify a Password for this script to work" 
    WScript.Quit() 
end if 

if strFTPServerFolder = "" then 
    WScript.Echo "You must specify a FTP Folder to access for this script to work" 
    WScript.Quit() 
end if 

if strFileToGet = "" then 
    WScript.Echo "You must specify a Filename to download for this script to work" 
    WScript.Quit() 
end if 



Call WriteFTPScript() 



Set objShell = WScript.CreateObject("WScript.Shell") 
returnCode = objShell.Run("cmd.exe /c ftp -s:" & chr(34) & strFTPScriptFileName & chr(34), 1, true) 

if (returnCode = 0) then 
    Wscript.echo("Your file has been downloaded.") 
else 
    Wscript.echo("An error has occured while attempting to download your file.") 
End if 

objShell.Run (strLocalFolderName) 
Set objShell = Nothing 



' ************************************************************************** 
' Creates the FTP script text file 
Function WriteFTPScript() 

    Dim objFSO, objMyFile 
    strFTPScriptFileName = strLocalFolderName & "\FTPScript.txt"  'File to be created to hold ftp script data 

    Set objFSO = CreateObject("Scripting.FileSystemObject") 

    If (objFSO.FileExists(strFTPScriptFileName)) Then 
      objFSO.DeleteFile (strFTPScriptFileName) 
    End If 

    Set objMyFile = objFSO.CreateTextFile(strFTPScriptFileName, True) 

    objMyFile.WriteLine ("open " & strFTPServerName) 
    objMyFile.WriteLine (strLoginID) 
    objMyFile.WriteLine (strPassword) 
    objMyFile.WriteLine ("cd " & strFTPServerFolder) 
    objMyFile.WriteLine ("lcd " & strLocalFolderName) 
    objMyFile.WriteLine ("get " & strFileToGet) 
    objMyFile.WriteLine ("bye") 


    objMyFile.Close 
    Set objFSO = Nothing 
    Set objMyFile = Nothing 

End Function 



' ************************************************************************** 
' Dialog box to select folder to download to 
Function GetLocalFolder() 

    Const BIF_returnonlyfsdirs = &H0001 
    Const BIF_editbox = &H0010 
    Dim wsh, objDlg, objF 

    Set objDlg = WScript.CreateObject("Shell.Application") 
    Set objF = objDlg.BrowseForFolder (&H0, "Select the destination folder to download FTP files to:", BIF_editbox + BIF_returnonlyfsdirs) 

    If IsValue(objF) Then 
     GetLocalFolder = objF.ParentFolder.ParseName(objF.Title).Path 
    Else 
     WScript.Echo "You MUST specify a folder to download files to. Application will now exit." 
     WScript.Quit 
    End If 

end function 


' ************************************************************************** 
' Verifies if the the object contains a value 
Function IsValue(obj) 
    Dim tmp 
    On Error Resume Next 
    tmp = " " & obj 
    If Err <> 0 Then 
     IsValue = False 
    Else 
     IsValue = True 
    End If 
    On Error GoTo 0 
End Function 



' ************************************************************************** 
' Verifies if the the object is a folder 
Function IsFolder(obj) 
    Dim objFSO 
    Set objFSO = CreateObject("Scripting.FileSystemObject") 

    if objFSO.IsFolder(obj) then 
     IsFolder = True 
    end if 



End Function 
+0

感謝您的腳本,但我不確定它適合我的應用程序。我的想法是,我可以自動爲客戶端設置ftp'dropbox',然後他們可以使用Windows資源管理器傳輸文件。 – Alex 2009-08-20 13:14:54

0

是的,有。 NetHood文件夾可以使用vbScript進行操作。有關更多信息,請參閱this forum thread。在XP Pro上,以下工作適用於我:

Option Explicit 
On Error Goto 0 

'ShellSpecialFolderConstants 
Const ssfNETHOOD = 19 '(&H13) Special Folder NETHOOD 

Dim objWSHShell, objShell, objFolder, objFolderItem, strNetHood 
Dim strShortcutName, strShortcutPath, objShortcut 

Set objWSHShell = CreateObject("Wscript.Shell") 
Set objShell = CreateObject("Shell.Application") 

Set objFolder = objShell.Namespace(ssfNETHOOD) 
Set objFolderItem = objFolder.Self 
strNetHood = objFolderItem.Path 

strShortcutName = "FTP to localhost" 
strShortcutPath = "ftp://[email protected]/" 

Set objShortcut = objWSHShell.CreateShortcut(strNetHood & "\" & strShortcutName & ".lnk") 
objShortcut.TargetPath = strShortcutPath 
objShortcut.Save 
相關問題