2009-08-20 7 views
1

Y at-il de toute façon que je puisse créer un petit fichier exe ou batch pour installer un nouveau 'My Network Place' dans Windows? C'est pour un site FTP si cela fait une différence.Ajouter par programme "Mon emplacement réseau" pour le site FTP?

XP sera principalement la machine cible mais si je peux trouver quelque chose qui fonctionnera sur Vista aussi c'est génial.

+0

Vous essayez de créer un script qui se connectera à un serveur FTP? – jgallant

+0

Non, j'essaie de créer un script qui ajoute automatiquement un emplacement réseau à un site ftp. Ensuite, l'utilisateur peut faire glisser et déposer des fichiers en utilisant Windows Explorer. – Alex

Répondre

0

J'ai écrit ce script pour me connecter à un FTP en utilisant un serveur proxy. Vous pouvez l'adapter à vos besoins. Il vous demande le nom de fichier et le dossier auquel vous essayez d'accéder. Il suffit de couper le code dont vous n'avez pas besoin, et vous devriez être prêt à partir.

Vous devrez également modifier la variable Nom du serveur FTP. Bonne codage:

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

Merci pour le script, mais je ne suis pas sûr que ce soit adapté à mon application. L'idée est que je peux configurer automatiquement la «boîte aux lettres» ftp pour les clients et ensuite ils peuvent transférer des fichiers en utilisant Windows Explorer. – Alex

0

Oui, il y a. Le dossier NetHood peut être manipulé avec vbScript. Reportez-vous au this forum thread pour plus d'informations. Ce qui suit pour moi sur 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 
Questions connexes