How to open an FTP folder in Windows via VBScript

2020-03-07 10:09发布

问题:

My code so far:

Set oShell = CreateObject("Shell.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
 set objShell = CreateObject("WScript.Shell")

'Copy Options: 16 = Yes to All
Const copyType = 16

'FTP Wait Time in ms
waitTime = 80000

FTPUser = "myuser"
FTPPass = "mypass"
FTPHost = "ftp IP"
FTPDir = "/Creative/"

strFTP = "ftp://" & FTPUser & "+" & FTPPass & "@" & FTPHost & FTPDir
Set objFTP = oShell.NameSpace(strFTP)

I am able to connect to my FTP folder, now I need to open that folder in Windows explorer.

回答1:

You can try like this way :

set objShell = CreateObject("WScript.Shell")
Login = "Your Username"
'If your username contains the @ symbol, and your web browser does not support this, you can substitute for the +
Login = Replace(Login,"@","+")
Password = "Your Pass"
FTPSERVER = "ftp.server.com"
RemoteFolder = "RemoteFolderName"
FTPURL = "ftp://"& Login &":"& Password &"@"& FTPSERVER &"/"& RemoteFolder
Connect2FTP = objShell.run("Explorer "& FTPURL ,1,False)

I have done an old vbscript to deal like that

Description :

You are on a different computer than you, either with friends or in a cybercafe? You want to add, modify, delete files or folders on your FTP server? No chance, you do not have programs on hand as FTP clients like (FileZilla, CuteFTP, FlashFXP. Etc ...) to access your Private FTP server ! No problem => FTP Explorer is the solution to turn your web browser or windows explorer in your FTP client !

I'd just translate this old french version to english version !

Hope that can help you !

Titre = "FTP EXPLORER © Hackoo © 2016"
    Set objIE = CreateObject( "InternetExplorer.Application" )
    objIE.Navigate "about:blank"
    objIE.Document.Title = Titre
    objIE.ToolBar        = False
    objIE.Resizable      = False
    objIE.StatusBar      = False
    objIE.Width          = 320
    objIE.Height         = 390
    ScreenWidth = objIE.document.ParentWindow.screen.width 
    ScreenHeight = objIE.document.ParentWindow.screen.height
    objIE.Left = (ScreenWidth  - objIE.Width ) \ 2
    objIE.Top  = (ScreenHeight - objIE.Height) \ 2
    Do While objIE.Busy
        WScript.Sleep 200
    Loop
    objIE.Document.Body.InnerHTML = "<div align=""center""><p><h3 style='color:Red'>UserName " _
    & "<br><input type=""text"" style='color:Blue' size=""20"" " _
    & "id=""Login"" value=""put your user name here""></h3></p>"_
    & "</p><p><h3 style='color:Red'>Password<br><input type=""password"" style='color:Blue' value=""Put your password here"" size=""20"" " _
    & "id=""Password""></h3></p><p><input type=" _
    & """hidden"" id=""OK"" name=""OK"" value=""0"">" _
    & "<h3 style='color:Red'>FTP Server " _
    & "<br><input type=""text"" style='color:Blue' size=""20"" " _
    & "id=""FTPSERVER"" value=""ftp.server.com""></h3>"_
    & "<br><h3 style='color:Red'>Remote Folder "_
    & "<br><input type=""text"" style='color:Blue' size=""20"" " _
    & "id=""DossierDistant"" value=""/www""></h3></p>"_
    & "<input type=""submit"" value="" Browse your FTP Folder"" " _
    & "onclick=""VBScript:OK.Value=1""></p></div>"
    objIE.Document.Body.Style.overflow = "auto"
    objIE.Document.body.style.backgroundcolor="lightGreen"
    objIE.Visible = True
    objIE.Document.All.Password.Focus
    On Error Resume Next
    Do While objIE.Document.All.OK.Value = 0
        WScript.Sleep 200
        If Err Then    
            IELogin = Array( "", "" )
            objIE.Quit
            Set objIE = Nothing
            wscript.quit
        End if
    Loop
    On Error Goto 0
    Set ws = CreateObject("wscript.Shell")
    Login = objIE.Document.All.Login.Value
    Login = Replace(Login,"@","+")'If your username contains the @ symbol, and your web browser does not support this, you can substitute for the +
    Password = objIE.Document.All.Password.Value
    FTPSERVER = objIE.Document.All.FTPSERVER.Value
    DossierDistant = objIE.Document.All.DossierDistant.Value
    URL = "ftp://"&Login&":"&Password&"@"&FTPSERVER&"/"&DossierDistant
    Connect2FTP = ws.run("Explorer "& URL ,1,False)
    objIE.Quit
ws.Popup "Connecting to "&qq(FTPSERVER)&" is in progress ..........",3,"Connecting to "&qq(FTPSERVER)&" is in progress ..........",64
    Set objIE = Nothing
    Set ws = Nothing
    Close("iexplore.exe")
'****************************************************
Sub Close(Process)
    Set Ws = CreateObject("Wscript.Shell")
    Command = "cmd /c Taskkill /F /IM "&Process&""
    Execution = Ws.Run(Command,0,True)
End Sub
'****************************************************
Function qq(strIn) 
    qq = Chr(34) & strIn & Chr(34)
End Function
'****************************************************


标签: vbscript ftp vb6