2009-08-20 4 views
1

어쨌든 Windows에서 새로운 '내 네트워크 환경'을 설치하기 위해 작은 exe 또는 배치 파일을 만들 수 있습니까? 그것이 ftp 사이트의 경우에는 차이가 있습니다.FTP 사이트에 '내 네트워크 환경'을 프로그래밍 방식으로 추가 하시겠습니까?

XP는 주로 대상 컴퓨터가되지만 Vista에서 작동하는 것을 찾을 수 있다면 너무 좋습니다.

+0

FTP 서버에 연결할 스크립트를 만들려고합니까? – jgallant

+0

아니요, 네트워크 사이트를 FTP 사이트에 자동으로 추가하는 스크립트를 만들려고합니다. 그런 다음 사용자는 Windows 탐색기를 사용하여 파일을 끌어다 놓을 수 있습니다. – Alex

답변

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

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 
관련 문제